Alexandre B A Villares 2018-06-12 20:46:15 -03:00
rodzic 07ad4fac29
commit 63a5aad2a9
3 zmienionych plików z 126 dodań i 0 usunięć

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=48, # 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
s164/s164.mov 100644

Plik binarny nie jest wyświetlany.

82
s164/s164.pyde 100644
Wyświetl plik

@ -0,0 +1,82 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME, OUTPUT = "s163", ".gif" # 180601
add_library('peasycam')
add_library('gifAnimation')
from gif_export_wrapper import *
GRID_SIZE = 10
def setup():
size(500, 500, P3D)
print_text_for_readme(SKETCH_NAME, OUTPUT)
border = 25
spacing = (width - border * 2) / GRID_SIZE
Ponto.spacing = spacing
for x in range(GRID_SIZE):
for y in range(GRID_SIZE):
Ponto.PONTOS.append(Ponto(border + spacing / 2 + x * spacing,
border + spacing / 2 + y * spacing))
for i in range(200):
for p in Ponto.PONTOS:
p.update()
for p in Ponto.PONTOS:
p.record(i)
cam = PeasyCam(this, 500)
def draw():
background(200)
translate(-width/2, -height/2, 0)
for i, (px1, py1, pz1, px2, py2, pz2) in eunumerate(Ponto.RECORD):
if i < frameCount * 100
if px1:
stroke(100, 0, 200)
line(px1, py1, pz1 * 2, px2, py2, pz2 *2)
with pushMatrix():
translate(0, 0, pz2 *2)
noStroke()
fill(0)
ellipse( px2, py2, 3, 3)
#if frameCount % 2:
#gif_export(GifMaker, frames=100, filename=SKETCH_NAME)
class Ponto():
PONTOS, RECORD = [], []
def __init__(self, x, y):
self.tx = int(random(100))
self.ty = int(random(100))
self.random_speed = 0.01
self.space = Ponto.spacing * 5
self.ox = x - self.space * noise(self.tx)
self.oy = y - self.space * noise(self.ty)
def update(self):
self.tx += self.random_speed
self.x = self.space * noise(self.tx)
self.ty += self.random_speed
self.y = self.space * noise(self.ty)
self.px = self.ox + self.x
self.py = self.oy + self.y
def record(self, i):
for other in Ponto.PONTOS:
if other != self and dist(other.px, other.py,
self.px, self.py) < Ponto.spacing * 1:
if i % 2: # só desenha a linha um frame sim outro não
Ponto.RECORD.append((other.px, other.py, i, self.px, self.py, i))
else:
Ponto.RECORD.append((None, None, None, self.px, self.py, i))
def print_text_for_readme(name, output):
println("""
![{0}]({0}/{0}{2})
{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:], output)
)