villares 2019-08-05 16:07:03 -03:00
rodzic 084ad33d84
commit 2ab21c5339
4 zmienionych plików z 138 dodań i 0 usunięć

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -0,0 +1,40 @@
"""
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
A helper for the Processing gifAnimation library https://github.com/extrapixel/gif-animation/tree/3.0
Download from https://github.com/villares/processing-play/blob/master/export_GIF/unzip_and_move_to_libraries_GifAnimation.zip
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
# add at the start of your sketch:
add_library('gifAnimation')
from gif_exporter import gif_export
# add 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=100, # quality range 0 - 255
delay=300, # this is quick
frames=0, # 0 will stop on keyPressed or frameCount >= 100000
finish=False): # force stop
global gifExporter
try:
gifExporter
except NameError:
gifExporter = GifMaker(this, filename + ".gif")
gifExporter.setRepeat(repeat)
gifExporter.setQuality(quality)
gifExporter.setDelay(delay)
gifExporter.addFrame()
if frames == 0:
if keyPressed and key == "e":
finish = True
if finish:
gifExporter.finish()
print("gif saved")
exit()

Wyświetl plik

@ -0,0 +1,49 @@
from random import choice
class Grid():
def __init__(self, pos, **args):
self.pos = PVector(*pos)
self.vel = PVector(choice((-1, 1, .5, -.5)), choice((.25, -.25)))
self.shapes = Grid.shapes((0, 0), **args)
self.space = args['space']
def update(self):
for sh in self.shapes:
shape(sh, self.pos.x, self.pos.y)
self.pos += self.vel * self.space
if self.pos.magSq() > width * height:
self.pos = self.pos * -1
@staticmethod
def shapes(pos, dims, space, elem):
gx, gy = pos
col_num, row_num = dims
result = []
half_w = col_num * space / 2.
half_h = row_num * space / 2.
for ix in range(col_num):
x = gx + ix * space + space / 2. - half_w
for iy in range(row_num):
y = gy + iy * space + space / 2. - half_h
noFill()
result.append(Grid.create_element(x, y, ix, iy, *elem))
return result
@staticmethod
def create_element(x, y, ix, iy, *args):
sh = args[0] # shape
si = args[1] # size
if int(si) % 3 == 0:
si *= 0.25 + 0.25 * ((ix + iy) % 3)
elif int(si) % 2 == 0:
si *= 0.5 + 0.5 * ((ix + iy) % 2)
if args[0] in (RECT, ELLIPSE):
return createShape(sh, x, y, si, si)
elif sh == TRIANGLE:
return createShape(TRIANGLE, x, y, x + si, y, x, y + si)
elif sh == TRIANGLES:
return createShape(TRIANGLE, x, y, x - si, y, x, y - si)

Wyświetl plik

@ -0,0 +1,49 @@
"""Grid study"""
from random import choice
add_library('GifAnimation')
from gif_exporter import gif_export
from grid import Grid
def setup():
size(500, 500)
rectMode(CENTER)
colorMode(HSB)
strokeJoin(ROUND)
strokeWeight(1.5)
create_grids()
frameRate(5)
def create_grids():
global grids
grids = []
for i in range(20):
d = int(random(3, 11)) # TODO: rectangular grids
sp = 20
x = int(random(-7, 8)) * sp
y = int(random(-7, 8)) * sp
si = random(10, 25)
sh = choice((ELLIPSE, ELLIPSE, RECT, RECT, TRIANGLE, TRIANGLES))
grids.append(Grid(pos=(x, y),
dims=(d, d),
space=sp,
elem=(sh, si))
)
def draw():
background(240)
translate(width / 2., height / 2.)
# scale(.5, .5)
for g in grids:
g.update()
gif_export(GifMaker)
def keyPressed():
if key == "s":
saveFrame("####.png")
if key == " ":
create_grids()