Alexandre B A Villares 2018-05-24 21:25:57 -03:00
rodzic 5410ea8c5e
commit 60850af53a
5 zmienionych plików z 121 dodań i 0 usunięć

Wyświetl plik

@ -8,6 +8,12 @@ If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/w
----
![s144](s144/s144.png)
144: [code](https://github.com/villares/sketch-a-day/tree/master/s144) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
----
![s143](s143/s143.png)
143: [code](https://github.com/villares/sketch-a-day/tree/master/s143) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]

Wyświetl plik

@ -0,0 +1,44 @@
"""
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
A helper for the Processing gifAnimation library (https://github.com/jordanorelli)
ported to Processing 3 by 01010101 (https://github.com/01010101)
Download the library from https://github.com/01010101/GifAnimation/archive/master.zip
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
Put at the start of your sketch:
add_library('gifAnimation')
from gif_exporter import gif_export
and at the end of draw():
gif_export(GifMaker)
"""
def gif_export(GifMaker, # gets a reference to the library
filename="exported", # .gif will be added
repeat=0, # 0 makes it an "endless" animation
quality=128, # quality range 0 - 255
delay=170, # this is quick
frames=0): # 0 will stop on keyPressed or frameCount >= 100000
global gifExporter
try:
gifExporter
except NameError:
gifExporter = GifMaker(this, filename + ".gif")
gifExporter.setRepeat(repeat)
gifExporter.setQuality(quality)
gifExporter.setDelay(delay)
gif_export._frame = frameCount
print("gif start")
gifExporter.addFrame()
if (frames == 0 and keyPressed or frameCount - gif_export._frame >= 100000) \
or (frames != 0 and frameCount - gif_export._frame >= frames):
gifExporter.finish()
#background(255)
print("gif saved")
del(gifExporter)
noLoop()
return False
else:
return True

BIN
s144/s143.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 48 KiB

BIN
s144/s144.gif 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 2.9 MiB

71
s144/s144.pyde 100644
Wyświetl plik

@ -0,0 +1,71 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME = "s144" # 180524
add_library('gifAnimation')
from gif_export_wrapper import *
def setup():
print_text_for_readme(SKETCH_NAME)
size(700, 700, P3D)
noFill()
ortho()
def draw():
background(200)
translate(width / 2, height / 2)
grid = 4
border = 0
space = (width - border * 2) / grid
for x in range(grid):
for y in range(grid):
px = border + space / 2 + x * space
py = border + space / 2 + y * space
with pushMatrix():
translate(px - width / 2, py - height / 2)
rotateX(PI * frameCount / 25.)
rotateY(PI * frameCount / 100.)
poly_shape(0, 0, TWO_PI / 4, rot=y + 1, gen=4, scaling=x)
gif_export(GifMaker, repeat=1, frames=99, filename=SKETCH_NAME)
def poly_shape(x, y, angle, rot, gen, scaling):
rnd = 0
with pushMatrix():
translate(x, y)
rotate(angle / rot)
# + random(-rnd, rnd)
radius = map(scaling, 0, 3, gen * 8, gen ** 2 * 2.7)
ps = createShape() # to create a polygon on a ps PShape object
ps.beginShape()
a = 0
while a < TWO_PI:
sx = cos(a) * radius
sy = sin(a) * radius
ps.vertex(sx + random(-rnd, rnd), sy + random(-rnd, rnd))
a += angle
ps.endShape(CLOSE) # end of PShape creation
if keyPressed:
shape(ps, 0, 0)
else:
with pushMatrix():
rotate(PI / 4)
box(radius * sqrt(2)) # Draw the PShape
if gen > 1: # if the recursion 'distance'/'depth' allows...
for i in range(ps.getVertexCount()): # for each vertex
pv = ps.getVertex(i) # gets vertex as a PVector
# recusively call poly_shape with a smaller D
poly_shape(pv.x, pv.y, angle, rot, gen - 1, scaling)
def keyPressed():
loop()
def print_text_for_readme(name):
println("""
![{0}]({0}/{0}.gif)
{1}: [code](https://github.com/villares/sketch-a-day/tree/master/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
""".format(name, name[1:])
)