diff --git a/2019/sketch_190517b/ensamble.py b/2019/sketch_190517b/ensamble.py new file mode 100644 index 00000000..ed77daee --- /dev/null +++ b/2019/sketch_190517b/ensamble.py @@ -0,0 +1,28 @@ +from random import choice +from polys import poly, poly_arc_augmented + + +class Ensamble: + + + def __init__(self, points, radius): + self.p_list = points + self.rad_list = radius + + def __eq__(self, other): + return self.p_list == other.p_list + + def plot(self): + rad_list = self.rad_list + noFill() + # strokeWeight(10) + # stroke(0, 100, 200) + # strokeJoin(ROUND) + # poly(self.p_list) + strokeWeight(10) + for i in range(len(rad_list)): + colorMode(HSB) + stroke(i 8, 255, 255) + poly_arc_augmented(self.p_list, rad_list) + rad_list[:] = [rad_list[-1]] + rad_list[:-1] + diff --git a/2019/sketch_190517b/gif_exporter.py b/2019/sketch_190517b/gif_exporter.py new file mode 100644 index 00000000..e908a2f1 --- /dev/null +++ b/2019/sketch_190517b/gif_exporter.py @@ -0,0 +1,43 @@ +""" +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=182, # 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) + # return False + # else: + # return True diff --git a/2019/sketch_190517b/polys.py b/2019/sketch_190517b/polys.py new file mode 100644 index 00000000..69e3f489 --- /dev/null +++ b/2019/sketch_190517b/polys.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +def poly(p_list, closed=True): + beginShape() + for p in p_list: + if p[2] == 0: + vertex(p[0], p[1]) + else: + vertex(*p) + if closed: + endShape(CLOSE) + else: + endShape() + +def poly_arc_augmented(p_list, r_list): + a_list = [] + for i1 in range(len(p_list)): + i2 = (i1 + 1) % len(p_list) + p1, p2, r1, r2 = p_list[i1], p_list[i2], r_list[i1], r_list[i2] + a = circ_circ_tangent(p1, p2, r1, r2) + a_list.append(a) + # ellipse(p1.x, p1.y, 2, 2) + + for i1 in range(len(a_list)): + i2 = (i1 + 1) % len(a_list) + p1, p2, r1, r2 = p_list[i1], p_list[i2], r_list[i1], r_list[i2] + #ellipse(p1.x, p1.y, r1 * 2, r1 * 2) + a1 = a_list[i1] + a2 = a_list[i2] + if a1 and a2: + start = a1 if a1 < a2 else a1 - TWO_PI + arc(p2.x, p2.y, r2 * 2, r2 * 2, start, a2) + else: + # println((a1, a2)) + ellipse(p1.x, p1.y, r1 * 2, r1 * 2) + ellipse(p2.x, p2.y, r2 * 2, r2 * 2) + + +def circ_circ_tangent(p1, p2, r1, r2): + d = dist(p1.x, p1.y, p2.x, p2.y) + ri = r1 - r2 + line_angle = atan2(p1.x - p2.x, p2.y - p1.y) + if d > abs(ri): + theta = asin(ri / float(d)) + + x1 = cos(line_angle - theta) * r1 + y1 = sin(line_angle - theta) * r1 + x2 = cos(line_angle - theta) * r2 + y2 = sin(line_angle - theta) * r2 + # line(p1.x - x1, p1.y - y1, p2.x - x2, p2.y - y2) + + x1 = -cos(line_angle + theta) * r1 + y1 = -sin(line_angle + theta) * r1 + x2 = -cos(line_angle + theta) * r2 + y2 = -sin(line_angle + theta) * r2 + line(p1.x - x1, p1.y - y1, p2.x - x2, p2.y - y2) + return (line_angle + theta) + else: + line(p1.x, p1.y, p2.x, p2.y) + return None diff --git a/2019/sketch_190517b/s190512a.gif b/2019/sketch_190517b/s190512a.gif new file mode 100644 index 00000000..3d528b6f Binary files /dev/null and b/2019/sketch_190517b/s190512a.gif differ diff --git a/2019/sketch_190517b/sketch_190517a.gif b/2019/sketch_190517b/sketch_190517a.gif new file mode 100644 index 00000000..1438ae94 Binary files /dev/null and b/2019/sketch_190517b/sketch_190517a.gif differ diff --git a/2019/sketch_190517b/sketch_190517b.gif b/2019/sketch_190517b/sketch_190517b.gif new file mode 100644 index 00000000..9993e7dd Binary files /dev/null and b/2019/sketch_190517b/sketch_190517b.gif differ diff --git a/2019/sketch_190517b/sketch_190517b.pyde b/2019/sketch_190517b/sketch_190517b.pyde new file mode 100644 index 00000000..5c3da4c5 --- /dev/null +++ b/2019/sketch_190517b/sketch_190517b.pyde @@ -0,0 +1,88 @@ +# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day +from __future__ import division +from random import choice +from ensamble import Ensamble + +add_library('GifAnimation') +from gif_exporter import gif_export + +SPACING, MARGIN = 100, 250 +grid = [] +N = 8 + +combinations = ((0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 1, 5), + (0, 1, 6), (0, 1, 7), (0, 2, 3), (0, 2, 4), + (0, 2, 5), (0, 2, 6), (0, 2, 7), (0, 3, 4), + (0, 3, 5), (0, 3, 6), (0, 3, 7), (0, 4, 5), + (0, 4, 6), (0, 4, 7), (0, 5, 6), (0, 5, 7), + (0, 6, 7), (1, 2, 3), (1, 2, 4), (1, 2, 5), + (1, 2, 6), (1, 2, 7), (1, 3, 4), (1, 3, 5), + (1, 3, 6), (1, 3, 7), (1, 4, 5), (1, 4, 6), + (1, 4, 7), (1, 5, 6), (1, 5, 7), (1, 6, 7), + (2, 3, 4), (2, 3, 5), (2, 3, 6), (2, 3, 7), + (2, 4, 5), (2, 4, 6), (2, 4, 7), (2, 5, 6), + (2, 5, 7), (2, 6, 7), (3, 4, 5), (3, 4, 6), + (3, 4, 7), (3, 5, 6), (3, 5, 7), (3, 6, 7), + (4, 5, 6), (4, 5, 7), (4, 6, 7), (5, 6, 7)) +def setup(): + global grid_list, rad_list + size(700, 700) + W, H = 700, 700 + X_LIST = [x for x in range(MARGIN, 1 + W - MARGIN, SPACING)] + Y_LIST = [y for y in range(MARGIN, 1 + H - MARGIN, SPACING)] + print X_LIST + grid_list = [] + for x in X_LIST: + for y in Y_LIST: + grid_list.append((x, y)) + grid_list.pop(len(grid_list) // 2) + rad_list = [20, 40, 60, 80, 100, 120, 140, 160] + + create_grid(grid_list, rad_list) + + + +def create_grid(grid_list, rad_list): + + for a, b, c in combinations: + va = PVector(*grid_list[a]) + vb = PVector(*grid_list[b]) + vc = PVector(*grid_list[c]) + e = Ensamble((va, vb, vc), [rad_list[a], rad_list[b], rad_list[c]]) + grid.append(e) + +def draw(): + translate(0, 50) + scale(1 / N, 1 / N) + background(250, 250, 240) + for x in range(N): + for y in range(N): + pushMatrix() + translate(x * 700, y * 700) + if x + y * N < 56: + grid[x + y * N].plot() + popMatrix() + + +def keyPressed(): + if key == " ": + grid[:] = [] + rad_list[:] = rad_list[1::]+[rad_list[0]] + create_grid(grid_list, rad_list) + if key == "s": + saveFrame("###.png") + if key == "g": + gif_export(GifMaker, filename=SKETCH_NAME, delay=1200) + +def settings(): + from os import path + global SKETCH_NAME + SKETCH_NAME = path.basename(sketchPath()) + OUTPUT = ".gif" + println( + """ +![{0}]({2}/{0}/{0}{1}) + +[{0}](https://github.com/villares/sketch-a-day/tree/master/{2}/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] +""".format(SKETCH_NAME, OUTPUT, year()) + )