diff --git a/2019/sketch_190323a/sketch_190323a.pyde b/2019/sketch_190323a/sketch_190323a.pyde index a9be84d2..5c2caf27 100644 --- a/2019/sketch_190323a/sketch_190323a.pyde +++ b/2019/sketch_190323a/sketch_190323a.pyde @@ -2,12 +2,15 @@ SKETCH_NAME, OUTPUT = "sketch_190323a", ".gif" """ -A retake of sketch 58 180228 + work from 190201 :) +A retake of sketch 58 180228 + work from sketch_190321 :) """ from collections import namedtuple import random as rnd import copy as cp +add_library('GifAnimation') +from gif_exporter import gif_export + SPACING, MARGIN = 60, 120 X_LIST, Y_LIST = [], [] # listas de posições para elementos desenho_atual, outro_desenho, desenho_inter, desenho_inicial = [], [], [], [] @@ -120,8 +123,8 @@ def draw(): ellipse(node.x, node.y, node.t_size/2, node.t_size/2) ellipse(other.x, other.y, node.s_weight, node.s_weight) - if frameCount % 4 == 0: - gif_export(GifMaker) + # if frameCount % 4 == 0: + # gif_export(GifMaker) def make_inter_nodes(amt): diff --git a/2019/sketch_190324a/gif_exporter.py b/2019/sketch_190324a/gif_exporter.py new file mode 100644 index 00000000..51c431df --- /dev/null +++ b/2019/sketch_190324a/gif_exporter.py @@ -0,0 +1,40 @@ +""" +Alexandre B A Villares http://abav.lugaralgum.com - GPL v3 + +A helper for the Processing gifAnimation library https://github.com/extrapixel/gif-animation/tree/3.0 +Download from https://github.com/villares/processing-play/blob/master/export_GIF/unzip_and_move_to_libraries_GifAnimation.zip +This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/ + +# add at the start of your sketch: + add_library('gifAnimation') + from gif_exporter import gif_export +# add 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=255, # quality range 0 - 255 + delay=200, # this is quick + frames=0, # 0 will stop on keyPressed or frameCount >= 100000 + finish=False): # force stop + global gifExporter + try: + gifExporter + except NameError: + gifExporter = GifMaker(this, filename + ".gif") + gifExporter.setRepeat(repeat) + gifExporter.setQuality(quality) + gifExporter.setDelay(delay) + + gifExporter.addFrame() + + if frames == 0: + if keyPressed and key == "e": + finish = True + + if finish: + gifExporter.finish() + print("gif saved") + exit() diff --git a/2019/sketch_190324a/sketch_190324a.gif b/2019/sketch_190324a/sketch_190324a.gif new file mode 100644 index 00000000..44ba4efc Binary files /dev/null and b/2019/sketch_190324a/sketch_190324a.gif differ diff --git a/2019/sketch_190324a/sketch_190324a.pyde b/2019/sketch_190324a/sketch_190324a.pyde new file mode 100644 index 00000000..04730f6a --- /dev/null +++ b/2019/sketch_190324a/sketch_190324a.pyde @@ -0,0 +1,173 @@ +# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day +SKETCH_NAME, OUTPUT = "sketch_190324a", ".gif" + +""" +A retake of sketch_190207a + work from sketch_190321 :) +Will stall sometimes... as there is an unsage while loop +selecting pointing nodes... +""" + +add_library('GifAnimation') +from gif_exporter import gif_export +add_library('peasycam') +from collections import namedtuple +import random as rnd +import copy as cp + +SPACING, MARGIN = 100, 100 +X_LIST, Y_LIST = [], [] # listas de posições para elementos +desenho_atual, outro_desenho, desenho_inter, desenho_inicial = [], [], [], [] +NUM_NODES = 32 # número de elementos do desenho / number of nodes +Node = namedtuple( + 'Node', 'x y t_size s_weight is_special points_to') +save_frames = False + +def setup(): + smooth(16) + size(600, 600, P3D) + colorMode(HSB) + rectMode(CENTER) + noFill() + cam = PeasyCam(this, 500) + X_LIST[:] = [x for x in range(MARGIN, 1 + width - MARGIN, SPACING)] + Y_LIST[:] = [y for y in range(MARGIN, 1 + height - MARGIN, SPACING)] + novo_desenho(desenho_atual) + desenho_inicial[:] = cp.deepcopy(desenho_atual) + +def keyPressed(): + global save_frames + if key == 's': + saveFrame("####.png") + if key == 'r': + make_nodes_point(desenho_atual) + if key == 'n': + novo_desenho(desenho_atual) + if key == ' ': + background(200) + +def novo_desenho(desenho): + """ + esvazia a lista elementos (setas e linhas) do desenho anterior + clears the list of nodes and creates a a new drawing appending desenho_atual, + a list of nodes/drawing elements: specials, connecting lines and lonely nodes + """ + desenho[:] = [] + for _ in range(NUM_NODES): + desenho.append(new_node()) + make_nodes_point(desenho) + outro_desenho[:] = cp.deepcopy(desenho) + make_nodes_point(outro_desenho) + + +def new_node(): + return Node( # elemento/"nó" uma namedtuple com: + rnd.choice(X_LIST), # x + rnd.choice(Y_LIST), # y + rnd.choice([10, 15, 20]), # t_size (tail/circle size) + rnd.choice([2, 3, 4]), # s_weight + # rnd.choice([True, False]), # is_special? (se é seta ou 'linha') + True, + [] # points_to... (lista com ref. a outro elem.)) + ) + +def make_nodes_point(desenho): + for node in desenho: # para cada elemento do desenho + node.points_to[:] = [] + random_node = rnd.choice(desenho) # sorteia o,utro elemento + while not ((node.x, node.y) != (random_node.x, random_node.y) + and dist(node.x, node.y, + random_node.x, random_node.y) <= SPACING * 2): + #print(node) + random_node = rnd.choice(desenho) + # 'aponta' para este elemento, acrescenta na sub_lista + node.points_to.append(random_node) + +def draw(): + translate(-width / 2, -height / 2) + global desenho_atual, outro_desenho + background(0) + fc = frameCount % 300 - 150 + if fc < 0: + desenho = desenho_atual + elif 0 <= fc < 149: + if frameCount % 10 == 0: + make_inter_nodes(map(fc, 0, 150, 0, 1)) + desenho = desenho_inter + elif fc == 149: + desenho_atual, outro_desenho = outro_desenho, desenho_atual + desenho = desenho_atual + if not mousePressed: + make_nodes_point(outro_desenho) + print("will reset") + else: + outro_desenho[:] = cp.deepcopy(desenho_inicial) + + # then draws black specials + for node in (n for n in desenho if n.is_special): + for other in node.points_to: # se estiver apontando para alguém + # strokeWeight(node.s_weight) + with pushMatrix(): + for i in range(-4, 11, 2): + stroke(48 + i * 8, 200, 200) + translate(0, 0, node.s_weight) + wave(node.x, node.y, other.x, other.y, + node.t_size - i, node.s_weight * 5 - i) + + # if frameCount % 4 == 0: + # gif_export(GifMaker) + + +def make_inter_nodes(amt): + desenho_inter[:] = [] + for n1, n2 in zip(desenho_atual, outro_desenho): + if n1.points_to: + p1x, p1y = n1.points_to[0].x, n1.points_to[0].y + else: + p1x, p1y = n1.x, n1.y + if n2.points_to: + p2x, p2y = n2.points_to[0].x, n2.points_to[0].y + else: + p2x, p2y = n2.x, n2.y + desenho_inter.append(Node( # elemento/"nó" uma namedtuple com: + n1.x, # x + n1.y, # y + n1.t_size, # t_size (tail/circle size) + n1.s_weight, # s_weight (espessura da linha) + n1.is_special, # is_special? (se é barra ou 'linha') + # cp.deepcopy(n1.points_to) + [PVector(lerp(p1x, p2x, amt), lerp(p1y, p2y, amt))] + )) + + +def wave(x1, y1, x2, y2, s=None, n=2): + """ + dois pares (x, y), largura, número de ondas + """ + L = dist(x1, y1, x2, y2) + if not s: + s = int(max(L / 5, 10)) + with pushMatrix(): + translate(x1, y1) + angle = atan2(x1 - x2, y2 - y1) + rotate(angle) + offset = 0 + dy = L / (n + 2) + line(0, 0, 0, dy) + for i in range(1, n + 1): + if i % 2: + line(0, i * dy, -s, i * dy + dy / 2) + line(0, i * dy + dy, -s, i * dy + dy / 2.) + else: + line(0, i * dy, s, i * dy + dy / 2) + line(0, i * dy + dy, s, i * dy + dy / 2.) + line(0, L, 0, L - dy) + +# print text to add to the project's README.md +def settings(): + println( + """ +![{0}](2019/{0}/{0}{1}) + +[{0}](https://github.com/villares/sketch-a-day/tree/master/2019/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] +""".format(SKETCH_NAME, OUTPUT) + ) diff --git a/README.md b/README.md index 1111d02c..6d7a46bd 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,17 @@ Get updates from my sort-of-weekly newsletter: [[sketch-mail](https://villares.o ## 2019 + +--- + +![sketch_190324a](2019/sketch_190324a/sketch_190324a.gif) + +[sketch_190324a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190324a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] + +A retake of sketch_190207a + work from sketch_190321 :) +Will stall sometimes... as there is an unsage while loop +selecting pointing nodes... (also present on 190323) + --- ![sketch_190323a](2019/sketch_190323a/sketch_190323a.gif)