diff --git a/README.md b/README.md index b82f9743..2eb21db5 100644 --- a/README.md +++ b/README.md @@ -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)] diff --git a/s153/gif_export_wrapper.py b/s153/gif_export_wrapper.py new file mode 100644 index 00000000..ed24d706 --- /dev/null +++ b/s153/gif_export_wrapper.py @@ -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 diff --git a/s153/s153.gif b/s153/s153.gif new file mode 100644 index 00000000..2718bad3 Binary files /dev/null and b/s153/s153.gif differ diff --git a/s153/s153.pyde b/s153/s153.pyde new file mode 100644 index 00000000..c86c3efa --- /dev/null +++ b/s153/s153.pyde @@ -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) + )