diff --git a/s325/arcs.py b/s325/arcs.py new file mode 100644 index 00000000..3196d91a --- /dev/null +++ b/s325/arcs.py @@ -0,0 +1,18 @@ +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, + BOTTOM + LEFT : HALF_PI, DOWN + 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) diff --git a/s325/node.py b/s325/node.py new file mode 100644 index 00000000..4da76916 --- /dev/null +++ b/s325/node.py @@ -0,0 +1,75 @@ +from random import choice +from arcs import quarter_circle, half_circle, circle_arc + +class Node(): + nodes = [] + + def __init__(self, x, y): + self.x = Node.border + Node.spacing / 2. + x * Node.spacing - width / 2. + self.y = Node.border + Node.spacing / 2. + y * Node.spacing - height / 2. + self.size_ = 1 + self.rot0 = choice((0, HALF_PI)) #, PI, PI + HALF_PI)) + self.rot1 = choice((HALF_PI , PI)) #, PI + HALF_PI)) + self.type = choice(("a", "c", "b", "c", "d", "d", "e" )) + + def plot(self, ang): + """ draws node """ + with pushMatrix(): + translate(self.x, self.y) + rotate(self.rot1) + noFill() #stroke(0) + siz = Node.spacing * self.size_ + t = 5 * cos(ang) + l = siz / 2. + a = l / 2. - t + c = l / 2. + t + # stroke(0, 0, 200, 50) + # rect(0, 0, siz, siz) + stroke(0, 50, 100) + for i in range(-4, 5, 4): # (-28, 29, 7): + stroke((frameCount + i * 8) % 256, 255, 255) + if self.type == "a": + #quarter_circle(l, l, siz - c + i, TOP + LEFT) + #quarter_circle(l, -l, siz - c + i, BOTTOM + LEFT) + i *= -1 + quarter_circle(l, l, c + i, TOP + LEFT) + quarter_circle(-l, -l, c + i, BOTTOM + RIGHT) + quarter_circle(-l, l, c + i, TOP + RIGHT) + quarter_circle(l, -l, c + i, BOTTOM + LEFT) + elif self.type == "b": + half_circle(-l, 0, a + i, RIGHT) + half_circle(l, 0, a + i, LEFT) + half_circle(0, l, a + i, TOP) + half_circle(0, -l, a + i, BOTTOM) + elif self.type == "c": + half_circle(l, 0, a + i, LEFT) + half_circle(-l, 0, a + i, RIGHT) + line(a + i, -l, a + i, l) + i *= -1 + line(-a + i, -l, -a + i, l) + elif self.type == "d": + quarter_circle(-l, l, siz - c + i, TOP + RIGHT) + quarter_circle(l, -l, siz - c + i, BOTTOM + LEFT) + i *= -1 + quarter_circle(-l, l, c + i, TOP + RIGHT) + quarter_circle(l, -l, c + i, BOTTOM + LEFT) + else: + line(-l, a + i, l, a + i) + line(a + i, -l, a + i, l) + i *= -1 + line(-l, -a + i, l, -a + i) + line(-a + i, -l, -a + i, l) + + + @classmethod + def init_grid(cls, grid_size, border): + cls.border = border + cls.spacing = (width - cls.border * 2) / grid_size + cls.nodes = [] + for x in range(grid_size): + for y in range(grid_size): + new_node = cls(x, y) + cls.nodes.append(new_node) + + + diff --git a/s325/s325.png b/s325/s325.png new file mode 100644 index 00000000..82005c1e Binary files /dev/null and b/s325/s325.png differ diff --git a/s325/s325.pyde b/s325/s325.pyde new file mode 100644 index 00000000..6880325e --- /dev/null +++ b/s325/s325.pyde @@ -0,0 +1,65 @@ +# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day +SKETCH_NAME = "s325" # 2018119 +OUTPUT = ".png" + +GRID_SIZE = 10 +BORDER = 50. + +add_library('peasycam') +from random import seed +from random import choice +from node import Node + +def setup(): + size(500, 500, P3D) + strokeWeight(2) + strokeCap(SQUARE) + rectMode(CENTER) + colorMode(HSB) + frameRate(10) + random_seed(101) + Node.init_grid(GRID_SIZE, BORDER) + cam = PeasyCam(this, 600) + +def draw(): + #translate(width/2, height/2) + translate(0, 0, -160) + background(0) + ang = 0 #frameCount/31. #map(mouseX, 0, width, 0, TWO_PI) + for ang in range(0, 34, 8): + with pushMatrix(): + translate(0, 0, ang * 10) + for node in Node.nodes: + node.plot(ang/10.) + + # if ang < TWO_PI: + # pass + # saveFrame("###.png") + # else: + # noLoop() + +def keyPressed(): + if key == "n": + Node.init_grid(GRID_SIZE, BORDER) + if key == "s": saveFrame("###.png") + + +def random_seed(s=None): + global rnd_seed + if s: + rnd_seed = s + seed(rnd_seed) + randomSeed(rnd_seed) + else: + seed(rnd_seed) + randomSeed(rnd_seed) + +# print text to add to the project's README.md +def settings(): + 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(SKETCH_NAME, SKETCH_NAME[1:], OUTPUT) + )