Alexandre B A Villares 2018-07-30 10:19:38 -03:00
rodzic 02b9384912
commit 1239f2afae
3 zmienionych plików z 84 dodań i 34 usunięć

Wyświetl plik

@ -0,0 +1,48 @@
"""
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,
finish=False,
): # 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 finish:
gifExporter.finish()
noLoop()
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
s213/s213.gif 100644

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -1,13 +1,13 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day # Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
# s211 20180728 # s213 20180730
from gif_export_wrapper import * from gif_export_wrapper import *
add_library('gifAnimation') add_library('gifAnimation')
add_library('peasycam') add_library('peasycam')
GRID_SIZE = 16 GRID_SIZE = 17
SKETCH_NAME = "s211" SKETCH_NAME = "s213"
OUTPUT = ".png" OUTPUT = ".gif"
def setup(): def setup():
# print_text_for_readme(SKETCH_NAME, OUTPUT) # print_text_for_readme(SKETCH_NAME, OUTPUT)
@ -25,36 +25,37 @@ def setup():
for y in range(GRID_SIZE): for y in range(GRID_SIZE):
for z in range(GRID_SIZE): for z in range(GRID_SIZE):
Node.nodes.append(Node(x, y, z)) Node.nodes.append(Node(x, y, z))
# Node.rooms is a list of spaced nodes inside the grid # Node.walls is a list of nodes on the cube surface
Node.rooms = [node for node in Node.nodes end_pos = GRID_SIZE - 1
if node.ix % 2 == 1 and Node.walls = [node for node in Node.nodes
node.iy % 2 == 1 and if node.ix == 0 or node.ix == end_pos
node.iz % 2 == 1] or node.iy == 0 or node.iy == end_pos
for node in Node.rooms: or node.iz == 0 or node.iz == end_pos
node.cor = color(0, 0, 255) ]
def draw(): def draw():
lights() lights()
# arbitray rotation # arbitray rotation
rotate(-1, 1/2, 1, 1/2) rotate(-0.5, 1/2, 1, 1/2)
background(100) background(100)
# angle based on frameCount to animate box sizes # angle based on frameCount to animate box sizes
ang = frameCount/10. ang = frameCount / 10.
for node in Node.nodes: for node in Node.walls:
node.plot() node.plot()
node.update(ang) node.update(ang)
# stop after a full size animatiom cycle # Save GIF frame & stop after a full size animatiom cycle
if ang < TWO_PI: # if ang < TWO_PI:
gif_export(GifMaker) # gif_export(GifMaker, filename=SKETCH_NAME)
else: # else:
gif_export(GifMaker, finish=True) # gif_export(GifMaker, finish=True)
class Node(): class Node():
nodes = [] nodes = []
rooms = [] walls = []
def __init__(self, x, y, z): def __init__(self, x, y, z):
self.ix = x self.ix = x
@ -69,19 +70,20 @@ class Node():
def plot(self): def plot(self):
""" draws box """ """ draws box """
if self.cor: s = Node.spacing * self.size_
stroke(0) if s > 0:
fill(self.cor) stroke(255)
fill(0)
else: else:
stroke(0) stroke(0)
fill(255, 100) fill(255)
with pushMatrix(): with pushMatrix():
translate(self.x, self.y, self.z) translate(self.x, self.y, self.z)
box(Node.spacing * self.size_) box(s)
def update(self, ang): def update(self, ang):
""" changing box size """ """ changing box size """
self.size_ = sin(self.x + self.y + self.z + ang) self.size_ = sin((self.x + self.y + self.z)/60. + ang)
def keyPressed(): def keyPressed():