villares 2019-08-04 23:42:50 -03:00
rodzic 51f01dc586
commit 592b86b01f
5 zmienionych plików z 148 dodań i 0 usunięć

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,53 @@
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()
strokeWeight(Grid.weight_rule(ix, iy, row_num))
# stroke(Grid.color_rule(ix, iy, row_num))
result.append(Grid.create_element(x, y, *elem))
return result
@staticmethod
def weight_rule(ix, iy, row_num):
return 0.5 + (ix + iy) % (1 + int(row_num / 4))
@staticmethod
def color_rule(ix, iy, row_num):
return color(row_num * 24 - (ix + iy) % 3 * 32 , 255, 255)
@staticmethod
def create_element(x, y, *args):
sh = args[0] # shape
si = args[1] # size
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)

Plik binarny nie jest wyświetlany.

Po

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

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(2)
create_grids()
frameRate(5)
def create_grids():
global grids
grids = []
for i in range(20):
d = int(random(4, 11))
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()

Wyświetl plik

@ -20,6 +20,12 @@ You may also support my artistic work, open teaching resources and research with
---
![sketch_1900804a](2019/sketch_190804a/sketch_190804a.gif)
[sketch_190804a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190804a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---
![sketch_1900803a](2019/sketch_190803a/sketch_190803a.gif)
[sketch_190803a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190803a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]