diff --git a/s161_plus_gif_exporter/s161.gif b/s161_plus_gif_exporter/s161.gif new file mode 100644 index 00000000..76a77bc8 Binary files /dev/null and b/s161_plus_gif_exporter/s161.gif differ diff --git a/s161_plus_gif_exporter/s161_.gif b/s161_plus_gif_exporter/s161_.gif new file mode 100644 index 00000000..cf2315a3 Binary files /dev/null and b/s161_plus_gif_exporter/s161_.gif differ diff --git a/s161_plus_gif_exporter/s161_plus_gif_exporter.pde b/s161_plus_gif_exporter/s161_plus_gif_exporter.pde new file mode 100644 index 00000000..233a2156 --- /dev/null +++ b/s161_plus_gif_exporter/s161_plus_gif_exporter.pde @@ -0,0 +1,49 @@ +import gifAnimation.*; +GifMaker gifExporter; + +float x, y; // posição x, posição y +float px, py; // posição x anterior, posição y anterior +float tempoX = 0; // declarando a variável global tempoX e inicializando com 0 +float tempoY = 10; // declarando a variável global tempoY e inicializando com 10 + +void setup() { + size(500, 500); // define o tamanho da tela em pixels. Largura X Altura + x = width * noise(tempoX); // calcula a posição x inicial + y = height * noise(tempoY); // calcula a posição y inicial + + gifExporter = new GifMaker(this, "s161.gif"); + gifExporter.setRepeat(0); + gifExporter.setDelay(170); + gifExporter.setQuality(255); +} + +void draw() { + background(0); + px = x; // guarda a posição x na variável px + py = y; // guarda a posição y na variável py + x = width * noise(tempoX); // atualiza a posição x sorteando um valor + y = height * noise(tempoY); // atualiza a posição y sorteando um valor + olho(x, y, dist(px, py, x, y)*100); // desenha uma linha entre os pontos (px, py) e (x, y) + // incrementa os tempos a cada frame + tempoX = tempoX + 0.005; + tempoY = tempoY + 0.005; + + gifExporter.addFrame(); + if (frameCount == 200) { + gifExporter.finish(); + exit(); + } +} + +void olho(float x, float y, float tamanho) { + noStroke(); + // branco + fill(255); + ellipse(x, y, tamanho, tamanho/2); + // iris + fill(random(256), random(256), random(256)); + ellipse(x, y, tamanho*.40, tamanho*.40); + // pupila + fill(0); + ellipse(x, y, tamanho*.10, tamanho*.10); +} diff --git a/s163/gif_export_wrapper.py b/s163/gif_export_wrapper.py new file mode 100644 index 00000000..ed24d706 --- /dev/null +++ b/s163/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/s163/s163.gif b/s163/s163.gif new file mode 100644 index 00000000..d4a88ad2 Binary files /dev/null and b/s163/s163.gif differ diff --git a/s163/s163.pyde b/s163/s163.pyde new file mode 100644 index 00000000..a56ce205 --- /dev/null +++ b/s163/s163.pyde @@ -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 px1, py1, pz1, px2, py2, pz2 in Ponto.RECORD: + 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: + pass + 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) + )