diff --git a/2019/sketch_190202a/3469.png b/2019/sketch_190202a/3469.png new file mode 100644 index 00000000..6d6acd8b Binary files /dev/null and b/2019/sketch_190202a/3469.png differ diff --git a/2019/sketch_190202a/6854.png b/2019/sketch_190202a/6854.png new file mode 100644 index 00000000..caed9a24 Binary files /dev/null and b/2019/sketch_190202a/6854.png differ diff --git a/2019/sketch_190202a/7078.png b/2019/sketch_190202a/7078.png new file mode 100644 index 00000000..9e65e4fd Binary files /dev/null and b/2019/sketch_190202a/7078.png differ diff --git a/2019/sketch_190202a/7202.png b/2019/sketch_190202a/7202.png new file mode 100644 index 00000000..2d2df766 Binary files /dev/null and b/2019/sketch_190202a/7202.png differ diff --git a/2019/sketch_190202a/7509.png b/2019/sketch_190202a/7509.png new file mode 100644 index 00000000..b732a37a Binary files /dev/null and b/2019/sketch_190202a/7509.png differ diff --git a/2019/sketch_190202a/7621.png b/2019/sketch_190202a/7621.png new file mode 100644 index 00000000..6f9f4757 Binary files /dev/null and b/2019/sketch_190202a/7621.png differ diff --git a/2019/sketch_190202a/7748.png b/2019/sketch_190202a/7748.png new file mode 100644 index 00000000..4a496686 Binary files /dev/null and b/2019/sketch_190202a/7748.png differ diff --git a/2019/sketch_190202a/8068.png b/2019/sketch_190202a/8068.png new file mode 100644 index 00000000..e4cb1a85 Binary files /dev/null and b/2019/sketch_190202a/8068.png differ diff --git a/2019/sketch_190202a/arcs.py b/2019/sketch_190202a/arcs.py new file mode 100644 index 00000000..259ccfd7 --- /dev/null +++ b/2019/sketch_190202a/arcs.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- + +ROTATION = {0: 0, + BOTTOM: 0, + DOWN: 0, + 1: HALF_PI, + LEFT: HALF_PI, + 2: PI, + TOP: PI, + UP: PI, + 3: PI + HALF_PI, + RIGHT: PI + HALF_PI, + BOTTOM + RIGHT: 0, + DOWN + RIGHT: 0, + DOWN + LEFT: HALF_PI, + BOTTOM + LEFT: HALF_PI, + TOP + LEFT: PI, + UP + LEFT: PI, + TOP + RIGHT: PI + HALF_PI, + UP + RIGHT: PI + HALF_PI, + } + +def quarter_circle(x, y, radius, quadrant): + circle_arc(x, y, radius, ROTATION[quadrant], HALF_PI) + +def half_circle(x, y, radius, quadrant): + circle_arc(x, y, radius, ROTATION[quadrant], PI) + +def circle_arc(x, y, radius, start_ang, sweep_ang): + arc(x, y, radius * 2, radius * 2, start_ang, start_ang + sweep_ang) + +def poly_arc(x, y, radius, start_ang, sweep_ang, num_points=2): + angle = sweep_ang / int(num_points) + a = start_ang + with beginShape(): + while a <= start_ang + sweep_ang: + sx = x + cos(a) * radius + sy = y + sin(a) * radius + vertex(sx, sy) + a += angle + +def arc_poly(x, y, d, _, start_ang, end_ang, num_points=5): + sweep_ang = end_ang - start_ang + angle = sweep_ang / int(num_points) + a = start_ang + with beginShape(): + while a <= end_ang: + sx = x + cos(a) * d / 2 + sy = y + sin(a) * d / 2 + vertex(sx, sy) + a += angle + +def bar(x1, y1, x2, y2, thickness=None, shorter=0, ends=(1, 1)): + """ + O código para fazer as barras, dois pares (x, y), + um parâmetro de encurtamento: shorter + """ + L = dist(x1, y1, x2, y2) + if not thickness: + thickness = 10 + with pushMatrix(): + translate(x1, y1) + angle = atan2(x1 - x2, y2 - y1) + rotate(angle) + offset = shorter / 2 + line(thickness / 2, offset, thickness / 2, L - offset) + line(-thickness / 2, offset, -thickness / 2, L - offset) + if ends[0]: + half_circle(0, offset, thickness / 2, UP) + if ends[1]: + half_circle(0, L - offset, thickness / 2, DOWN) + +def var_bar(p1x, p1y, p2x, p2y, r1, r2=None): + if r2 is None: + r2 = r1 + d = dist(p1x, p1y, p2x, p2y) + if d > 0: + with pushMatrix(): + translate(p1x, p1y) + angle = atan2(p1x - p2x, p2y - p1y) + rotate(angle + HALF_PI) + ri = r1 - r2 + beta = asin(ri / d) + HALF_PI + x1 = cos(beta) * r1 + y1 = sin(beta) * r1 + x2 = cos(beta) * r2 + y2 = sin(beta) * r2 + with pushStyle(): + noStroke() + beginShape() + vertex(-x1, -y1) + vertex(d - x2, -y2) + vertex(d, 0) + vertex(d - x2, +y2) + vertex(-x1, +y1) + vertex(0, 0) + endShape(CLOSE) + line(-x1, -y1, d - x2, -y2) + line(-x1, +y1, d - x2, +y2) + arc(0, 0, r1 * 2, r1 * 2, + -beta - PI, beta - PI) + arc(d, 0, r2 * 2, r2 * 2, + beta - PI, PI - beta) diff --git a/2019/sketch_190202a/sketch_190202a.gif b/2019/sketch_190202a/sketch_190202a.gif new file mode 100644 index 00000000..c677c3d1 Binary files /dev/null and b/2019/sketch_190202a/sketch_190202a.gif differ diff --git a/2019/sketch_190202a/sketch_190202a.pyde b/2019/sketch_190202a/sketch_190202a.pyde new file mode 100644 index 00000000..4cd7ba2f --- /dev/null +++ b/2019/sketch_190202a/sketch_190202a.pyde @@ -0,0 +1,99 @@ +# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day +SKETCH_NAME, OUTPUT = "sketch_190202a", ".gif" + +""" +A retake of sketch 57 180226 + work from 190201 :) +""" + +from arcs import var_bar +from collections import namedtuple +import random as rnd + +SPACING, MARGIN = 120, 120 +X_LIST, Y_LIST = [], [] # listas de posições para elementos +DESENHO = [] # lista dos elementos, 'nodes', do desenho +NUM_NODES = 8 # número de elementos do desenho / number of nodes +Node = namedtuple( + 'Node', ['x', 'y', 't_size', 's_weight', 'is_special', 'points_to']) + +def setup(): + size(600, 600) + rectMode(CENTER) + noFill() + 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) + #println("'s' to save, and 'n' for a new drawing") + +def keyPressed(): + if key == 's': + saveFrame("####.png") + if key == 'r': + make_nodes_point(DESENHO) + if key == 'n': + novo_desenho(DESENHO) + +def novo_desenho(desenho): + """ + esvazia a lista elementos (barras arredondadas e linhas) do desenho anterior + clears the list of nodes and creates a a new drawing appending DESENHO, + a list of nodes/drawing elements: special bars, connecting lines and lonely nodes + """ + desenho[:] = [] + for _ in range(NUM_NODES): + desenho.append(new_node()) + make_nodes_point(desenho) + +def new_node(): + return Node( # elemento/"nó" uma namedtuple com: + rnd.choice(X_LIST), # x + rnd.choice(Y_LIST), # y + rnd.choice([10, 20, 30]), # t_size (tail/circle size) + rnd.choice([2, 4, 6]), # s_weight (espessura da linha) + rnd.choice([True, False]), # is_special? (se é barra ou 'linha') + [] # 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 outro elemento + if (node.x, node.y) != (random_node.x, random_node.y): + # 'aponta' para este elemento, acrescenta na sub_lista + node.points_to.append(random_node) + +def draw(): + background(200) + # draws white 'lines', non-specials, first. + for node in (n for n in DESENHO if not n.is_special): + for other in node.points_to: # se estiver apontando para alguém + strokeWeight(node.s_weight) + stroke(255) + line(node.x, node.y, other.x, other.y) + # desenha o círculo (repare que só em nós que 'apontam') + ellipse(node.x, node.y, node.t_size, node.t_size) + # then draws 'lonely nodes' in red (nodes that do not point anywhere) + for node in (n for n in DESENHO if not n.points_to): + strokeWeight(node.s_weight) + stroke(255, 0, 0) # red stroke for lonely nodes + if node.is_special: + rect(node.x, node.y, node.t_size, node.t_size, node.s_weight * 3) + else: + ellipse(node.x, node.y, node.t_size, node.t_size) + # 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) + stroke(0) + var_bar(node.x, node.y, other.x, other.y, + node.t_size, node.s_weight * 5) + +# 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) + )