Alexandre B A Villares 2018-05-26 10:44:21 -03:00
rodzic 9755f882bf
commit 96d3e85415
4 zmienionych plików z 123 dodań i 1 usunięć

Wyświetl plik

@ -8,11 +8,16 @@ If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/w
----
![s146](s146/s146.gif)
146: [code](https://github.com/villares/sketch-a-day/tree/master/s146) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
----
![s145](s145/s145.png)
145: [code](https://github.com/villares/sketch-a-day/tree/master/s145) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
----
![s144](s144/s144.png)

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
s146/s146.gif 100644

Plik binarny nie jest wyświetlany.

Po

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

73
s146/s146.pyde 100644
Wyświetl plik

@ -0,0 +1,73 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME, OUTPUT = "s146", ".gif" # 180526
add_library('gifAnimation')
from gif_export_wrapper import *
GRID_SIZE = 16
def setup():
size(500, 500)
print_text_for_readme(SKETCH_NAME, OUTPUT)
border = 20
spacing = (width - border * 2) / GRID_SIZE
Ponto.spacing = spacing
for j in range(GRID_SIZE):
for i in range(GRID_SIZE):
Ponto.PONTOS.append(Ponto(border + spacing / 2 + i * spacing,
border + spacing / 2 + j * spacing)
)
def draw():
fill(200, 50)
noStroke()
rect(0, 0, width, height)
for p in Ponto.PONTOS:
p.update()
if frameCount > 100 and not frameCount % 2:
gif_export(GifMaker, frames=200, filename=SKETCH_NAME)
class Ponto():
PONTOS = []
def __init__(self, x, y):
self.x = x
self.y = y
self.px = x
self.py = y
def update(self):
rx = random(-0.5, 0.5)
ry = random(-0.5, 0.5)
if abs(self.px + rx - self.x) < Ponto.spacing * 0.25:
self.px += rx
if abs(self.py + ry - self.y) < Ponto.spacing * 0.25:
self.py += ry
self.plot()
def plot(self):
noStroke()
fill(100, 100)
s = 10
for p in Ponto.PONTOS:
d = dist(p.px, p.py, self.px, self.py)
if Ponto.spacing * .9 < d <= Ponto.spacing * 1.2:
stroke(0)
line(p.px, p.py, self.px, self.py)
elif d < Ponto.spacing * 0.9:
stroke(255)
line(p.px, p.py, self.px, self.py)
fill(128, 0 ,0)
noStroke()
ellipse(self.px, self.py, 4, 4)
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)
)