kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
3d8cd20485
commit
440d2e8667
|
|
@ -8,6 +8,12 @@ If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/w
|
|||
|
||||
----
|
||||
|
||||

|
||||
|
||||
151: [code](https://github.com/villares/sketch-a-day/tree/master/s151) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
150: [code](https://github.com/villares/sketch-a-day/tree/master/s150) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 9.1 MiB |
|
|
@ -0,0 +1,76 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
SKETCH_NAME, OUTPUT = "s151", ".gif" # 180530
|
||||
|
||||
add_library('gifAnimation')
|
||||
from gif_export_wrapper import *
|
||||
|
||||
GRID_SIZE = 4
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
print_text_for_readme(SKETCH_NAME, OUTPUT)
|
||||
border = 25
|
||||
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, 5)
|
||||
noStroke()
|
||||
rect(0, 0, width, height)
|
||||
for p in Ponto.PONTOS:
|
||||
p.update()
|
||||
noLoop()
|
||||
|
||||
if frameCount > 100 and not frameCount % 2:
|
||||
gif_export(GifMaker, frames=200, filename=SKETCH_NAME)
|
||||
|
||||
class Ponto():
|
||||
PONTOS = []
|
||||
|
||||
def __init__(self, x, y):
|
||||
self.ox = x
|
||||
self.oy = y
|
||||
self.tx = int(random(100))
|
||||
self.ty = random(100)
|
||||
self.random_speed = 0.01
|
||||
while int(width/10*noise(self.tx)) > 10:
|
||||
self.tx += 1
|
||||
while int(height/10*noise(self.ty)) > 10:
|
||||
self.ty += 1
|
||||
print(
|
||||
int(width/10h*noise(self.tx)),
|
||||
int(width/10*noise(self.ty))
|
||||
)
|
||||
|
||||
def update(self):
|
||||
self.tx += self.random_speed
|
||||
self.x = width/10*noise(self.tx)
|
||||
self.ty += self.random_speed
|
||||
self.y = height/10*noise(self.ty)
|
||||
self.plot()
|
||||
|
||||
def plot(self):
|
||||
fill(0)
|
||||
noStroke()
|
||||
with pushMatrix():
|
||||
translate(self.ox, self.oy)
|
||||
ellipse(self.x, self.y, 5, 5)
|
||||
|
||||
|
||||
|
||||
def keyPressed():
|
||||
redraw()
|
||||
|
||||
def print_text_for_readme(name, output):
|
||||
println("""
|
||||

|
||||
|
||||
{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)
|
||||
)
|
||||
Ładowanie…
Reference in New Issue