diff --git a/s362/s362_2894.png b/s362/s362_2894.png deleted file mode 100644 index 4e612fce..00000000 Binary files a/s362/s362_2894.png and /dev/null differ diff --git a/s362/s362_2926.png b/s362/s362_2926.png deleted file mode 100644 index fc5f23d4..00000000 Binary files a/s362/s362_2926.png and /dev/null differ diff --git a/s362/s362_2942.png b/s362/s362_2942.png deleted file mode 100644 index ab4474c7..00000000 Binary files a/s362/s362_2942.png and /dev/null differ diff --git a/s362/s362_2956.png b/s362/s362_2956.png deleted file mode 100644 index 6129cc64..00000000 Binary files a/s362/s362_2956.png and /dev/null differ diff --git a/s362/s362_2974.png b/s362/s362_2974.png deleted file mode 100644 index edc11b2c..00000000 Binary files a/s362/s362_2974.png and /dev/null differ diff --git a/s362/s362_3010.png b/s362/s362_3010.png deleted file mode 100644 index 04dba26e..00000000 Binary files a/s362/s362_3010.png and /dev/null differ diff --git a/s362/s362_3028.png b/s362/s362_3028.png deleted file mode 100644 index b6ec7391..00000000 Binary files a/s362/s362_3028.png and /dev/null differ diff --git a/s362/s362_3184.png b/s362/s362_3184.png deleted file mode 100644 index 21c25213..00000000 Binary files a/s362/s362_3184.png and /dev/null differ diff --git a/s362/s362_3225.png b/s362/s362_3225.png deleted file mode 100644 index 2f326171..00000000 Binary files a/s362/s362_3225.png and /dev/null differ diff --git a/s362/s362_3260.png b/s362/s362_3260.png deleted file mode 100644 index 95ca06b9..00000000 Binary files a/s362/s362_3260.png and /dev/null differ diff --git a/s362/s362_3303.png b/s362/s362_3303.png deleted file mode 100644 index e38ab5fc..00000000 Binary files a/s362/s362_3303.png and /dev/null differ diff --git a/s362/s362_3325.png b/s362/s362_3325.png deleted file mode 100644 index ca1fae7f..00000000 Binary files a/s362/s362_3325.png and /dev/null differ diff --git a/s362/s362_3347.png b/s362/s362_3347.png deleted file mode 100644 index 8cf3ca1f..00000000 Binary files a/s362/s362_3347.png and /dev/null differ diff --git a/s362/s362_3369.png b/s362/s362_3369.png deleted file mode 100644 index 36a62147..00000000 Binary files a/s362/s362_3369.png and /dev/null differ diff --git a/s362/s362_3416.png b/s362/s362_3416.png deleted file mode 100644 index 21c25213..00000000 Binary files a/s362/s362_3416.png and /dev/null differ diff --git a/s362/s362_3445.png b/s362/s362_3445.png deleted file mode 100644 index 2f326171..00000000 Binary files a/s362/s362_3445.png and /dev/null differ diff --git a/s362/s362_3478.png b/s362/s362_3478.png deleted file mode 100644 index 95ca06b9..00000000 Binary files a/s362/s362_3478.png and /dev/null differ diff --git a/s363/s363_388.png b/s363/s363_388.png deleted file mode 100644 index f2724b80..00000000 Binary files a/s363/s363_388.png and /dev/null differ diff --git a/s363/s363_485.png b/s363/s363_485.png deleted file mode 100644 index 068389fe..00000000 Binary files a/s363/s363_485.png and /dev/null differ diff --git a/s363/s363_524.png b/s363/s363_524.png deleted file mode 100644 index 2ea567d6..00000000 Binary files a/s363/s363_524.png and /dev/null differ diff --git a/s363/s363_583.png b/s363/s363_583.png deleted file mode 100644 index 35dc57b1..00000000 Binary files a/s363/s363_583.png and /dev/null differ diff --git a/s363/s363_590.png b/s363/s363_590.png deleted file mode 100644 index 408b1bac..00000000 Binary files a/s363/s363_590.png and /dev/null differ diff --git a/s363/s363_597.png b/s363/s363_597.png deleted file mode 100644 index ee656b59..00000000 Binary files a/s363/s363_597.png and /dev/null differ diff --git a/s363/s363_605.png b/s363/s363_605.png deleted file mode 100644 index 7006fae4..00000000 Binary files a/s363/s363_605.png and /dev/null differ diff --git a/s363/s363_611.png b/s363/s363_611.png deleted file mode 100644 index 86f563a4..00000000 Binary files a/s363/s363_611.png and /dev/null differ diff --git a/s363/s363_672.png b/s363/s363_672.png deleted file mode 100644 index 2ea567d6..00000000 Binary files a/s363/s363_672.png and /dev/null differ diff --git a/s363/s363_708.png b/s363/s363_708.png deleted file mode 100644 index 068389fe..00000000 Binary files a/s363/s363_708.png and /dev/null differ diff --git a/s363/s363_798.png b/s363/s363_798.png deleted file mode 100644 index f2724b80..00000000 Binary files a/s363/s363_798.png and /dev/null differ diff --git a/s365/arcs.py b/s365/arcs.py new file mode 100644 index 00000000..bcc68693 --- /dev/null +++ b/s365/arcs.py @@ -0,0 +1,28 @@ +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) diff --git a/s365/cell.py b/s365/cell.py new file mode 100644 index 00000000..ed24ce01 --- /dev/null +++ b/s365/cell.py @@ -0,0 +1,178 @@ +# -*- coding: utf-8 -*- +from random import choice +from arcs import quarter_circle, half_circle, circle_arc + + +class Cell(): + grid = dict() + # neighbours list + NL = ((-1, -1), (+0, -1), (+1, -1), + (-1, +0), (+0, +0), (+1, +0), + (-1, +1), (+0, +1), (+1, +1)) + ONL = ((+0, -1), + (-1, +0), (+0, +0), (+1, +0), + (+0, +1)) + DNL = ((-1, -1), (+1, -1), + (+0, +0), + (-1, +1), (+1, +1)) + + def __init__(self, index, cell_size, state=False): + self.index = index + self.state = state + self.size_ = cell_size + self.mouse_down = False + self.variation = choice(("a", "b", "c")) + if Cell.rotated_start: + self.ang = choice((0, 1, 2, 3)) + else: + self.ang = 0 + self.calculate_pos() + + def calculate_pos(self): + i, j = self.index + self.pos = PVector(self.size_ / 2 + i * self.size_, + self.size_ / 2 + j * self.size_) + + def update(self, mx, my): + if keyPressed and keyCode == SHIFT and self.ang > 0: + self.ang -= (1 / 4.) + # mouse over & selection treatment + hs = self.size_ / 2 + px, py = self.pos.x, self.pos.y + self.mouse_on = (px - hs < mx < px + hs and + py - hs < my < py + hs) + if self.mouse_on and mousePressed: + self.mouse_down = True + + elif self.mouse_down: + self.state = not self.state + self.mouse_down = False + + self.find_type(Cell.ONL) + + def plot(self, mode): + if self.state: + strokeWeight(1) + if mode == 1: + self.variation = "a" + if mode == 2: + self.variation = "b" + if mode == 3: + self.variation = "c" + if mode == 4: + self.variation = choice(("a", "b", "c")) + if mode == -1: + fill(0) + noStroke() + rect(self.pos.x, self.pos.y, self.size_, self.size_) + noFill() + + """ draws node """ + with pushMatrix(): + translate(self.pos.x, self.pos.y) + rotate(HALF_PI * self.ang) + noFill() # stroke(0) + siz = self.size_ + l = siz / 2. + a = l / 2. - 1 + c = l / 2. + 1 + # base rect + #stroke(0, 0, 200, 50) + #rect(0, 0, siz, siz) + #text(self.type, 0, 0) + # inv t & inv l + if (self.type == "11110" or + self.type == "10110" or + self.type == "00101"): + rotate(PI) + if (self.type == "11101" or + self.type == "01110" or + self.type == "11100" or + self.type == "00110"): # t r & i + rotate(HALF_PI) + if (self.type == "10111" or + self.type == "00111" or + self.type == "01100"): # t l + rotate(PI + HALF_PI) + + for i in range(Cell.step_start, + Cell.step_end, + Cell.step): # (-28, 29, 7): + stroke(32, 64 + i * 8, 64 - i * 8) + if self.type == "11111" and self.variation == "a": + 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) + if self.type == "11111" and self.variation == "b": + #ellipse(0, 0, (a + i) * 2, (a + i) * 2) + 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) + if self.type == "11111" and self.variation == "c": + line(+a - i, -l, +a - i, l) + line(-a + i, -l, -a + i, l) + half_circle(-l, 0, a - i, RIGHT) + half_circle(l, 0, a - i, LEFT) + # ellipse(0, 0, (a + i) * 2, (a + i) * 2) + elif (self.type == "01111" or # t + self.type == "11110" or + self.type == "11101" or + self.type == "10111"): # t + #line(-l, a + i, l, a + i) + line(-l, -a + i, l, -a + i) + #half_circle(-l, 0, a - i, RIGHT) + #half_circle(l, 0, a - i, LEFT) + #half_circle(0, l, a - i, TOP) + 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) + #ellipse(0, 0, (a + i) * 2, (a + i) * 2) + elif self.type == "10101" or self.type == "01110": + if self.variation in "ab": + line(+a - i, -l, +a - i, l) + line(-a + i, -l, -a + i, l) + elif self.variation == "c": + half_circle(0, l, a - i, TOP) + half_circle(0, -l, a - i, BOTTOM) + ellipse(0, 0, (a + i) * 2, (a + i) * 2) + elif (self.type == "01101" or + self.type == "10110" or + self.type == "00111" or + self.type == "11100"): # l + if self.variation == "a": + # stroke(255, 0, 0) + # text(self.type, 0, 0) + half_circle(-l, 0, a - i, RIGHT) + half_circle(0, l, a - i, TOP) + else: + # stroke(0, 255, 0) + # text(self.type, 0, 0) + quarter_circle(-l, l, siz - c - i, TOP + RIGHT) + i *= -1 + quarter_circle(-l, l, c - i, TOP + RIGHT) + #half_circle(-l, 0, a - i, RIGHT) + #half_circle(0, l, a - i, TOP) + elif (self.type == "01100" or + self.type == "00110" or + self.type == "00101" or + self.type == "10100"): + line(+a - i, -l, +a - i, 0) + line(-a + i, -l, -a + i, 0) + half_circle(0, 0, a - i, BOTTOM) + elif self.type == "00100": + rect(0, 0, (a - i) * 2, (a - i) * 2, (a - i - 1)) + # ellipse(0, 0, (a + i) * 2.0, (a + i) * 2.0) + # ellipse(0, 0, (a - i) * 2.5, (a - i) * 2.5) + + def find_type(self, nbs): + i, j = self.index[0], self.index[1] + self.type = "" + for (ni, nj) in nbs: + nb = Cell.grid.get((i + ni, j + nj), None) + if nb and nb.state: + self.type += "1" + else: + self.type += "0" diff --git a/s365/s365.gif b/s365/s365.gif new file mode 100644 index 00000000..5d7530a6 Binary files /dev/null and b/s365/s365.gif differ diff --git a/s365/s365.pyde b/s365/s365.pyde new file mode 100644 index 00000000..f692e130 --- /dev/null +++ b/s365/s365.pyde @@ -0,0 +1,85 @@ +# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day +SKETCH_NAME = "s365" # 20181229 +OUTPUT = ".png" +mode = 0 + +from cell import Cell +from random import choice + +CELL_SIZE = 50 +Cell.step_start = -11 +Cell.step_end = 10 +Cell.step = 5 +Cell.rotated_start = False +modulus = 3 + +def setup(): + size(600, 600) + global grid_size + grid_size = width / CELL_SIZE + rectMode(CENTER) + strokeCap(SQUARE) + +def init_grid(f=None): + w, h = int(width // CELL_SIZE), int(height // CELL_SIZE) + for i in range(w): + for j in range(h): + if f == None: + f = lambda i, j: choice((True, False)) + Cell.grid[(i, j)] = Cell((i, j), CELL_SIZE, f(i, j)) + +def draw(): + background(200) + for c in Cell.grid.values(): + c.update(mouseX, mouseY) + for c in Cell.grid.values(): + c.plot(mode) + + +def keyPressed(): + global mode, modulus + if key == "s" or key == "S": + saveFrame(SKETCH_NAME + "_###.png") + if key != CODED and key in "01234567789": + mode = int(key) + if key == "-": + mode = -1 + if key == " ": + t = lambda i, j: True + f = lambda i, j: False + init_grid(choice((t, f))) + if key == "r": + init_grid() + if key == "x": + init_grid(lambda i, j: (i + j) % modulus) + if keyCode == LEFT and modulus > 2: + modulus -= 1 + if keyCode == RIGHT: + modulus += 1 + if key == "z": + move_grid() + if key == "R": + Cell.rotated_start = not Cell.rotated_start + +def move_grid(x=1, y=1): + w, h = width // CELL_SIZE, height // CELL_SIZE + new_grid = dict() + for i in range(w): + for j in range(h): + c = Cell.grid.get((i, j), None) + if c: + c.index = ((i + x) % w, (j + y) % h) + c.calculate_pos() + new_grid[c.index] = c + Cell.grid = new_grid + + +# 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) + )