Alexandre B A Villares 2018-06-02 18:43:04 -03:00
rodzic 04970cae3c
commit 8e8af2a797
4 zmienionych plików z 123 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
----
![s153](s153/s153.gif)
153: [code](https://github.com/villares/sketch-a-day/tree/master/s153) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
----
![s152](s152/s152.gif)
152: [code](https://github.com/villares/sketch-a-day/tree/master/s152) [[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=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
s153/s153.gif 100644

Plik binarny nie jest wyświetlany.

Po

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

73
s153/s153.pyde 100644
Wyświetl plik

@ -0,0 +1,73 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME, OUTPUT = "s153", ".gif" # 180602
add_library('gifAnimation')
from gif_export_wrapper import *
GRID_SIZE = 30
def setup():
size(500, 500)
background(0)
print_text_for_readme(SKETCH_NAME, OUTPUT)
border = 25
spacing = (width - border * 2) / GRID_SIZE
Ponto.spacing = spacing
a = 0
while a < TWO_PI:
x = cos(a) * spacing * 10
y = sin(a) * spacing * 10
Ponto.PONTOS.append(Ponto(width/2 + x, height/2 + y))
a += TWO_PI/60.
def draw():
#fill(200, 4)
#noStroke()
#rect(0, 0, width, height)
for p in Ponto.PONTOS:
p.update()
for p in Ponto.PONTOS:
p.plot()
#noLoop()
if frameCount > 200 and frameCount % 2:
gif_export(GifMaker, frames=200, filename=SKETCH_NAME)
class Ponto():
PONTOS = []
def __init__(self, x, y):
self.tx = int(random(100))
self.ty = int(random(100))
self.speed = 0.02
self.space = Ponto.spacing * 5
self.ox = x - self.space*noise(self.tx)
self.oy = y - self.space*noise(self.ty)
def update(self):
if frameCount > 300: rs = self.speed
else: rs = -self.speed
self.tx += rs
self.x = self.space*noise(self.tx)
self.ty += rs
self.y = self.space*noise(self.ty)
self.px = self.ox + self.x
self.py = self.oy + self.y
def plot(self):
for p in Ponto.PONTOS:
if p != self and dist(p.px, p.py,
self.px, self.py) < Ponto.spacing * 3:
if frameCount % 2: # só desenha a linha um frame sim outro não
colorMode(HSB)
stroke(4 * (frameCount % 64), 255, 255)
line(p.px, p.py, self.px, self.py)
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)
)