diff --git a/s218/s218.gif b/s218/s218.gif new file mode 100644 index 00000000..be3c9b3a Binary files /dev/null and b/s218/s218.gif differ diff --git a/s218/s218.pyde b/s218/s218.pyde index 089bffc1..842f63af 100644 --- a/s218/s218.pyde +++ b/s218/s218.pyde @@ -1,64 +1,76 @@ # Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day -# s216 20180802 +# s218 20180804 -from collections import namedtuple from random import randint from gif_export_wrapper import * add_library('gifAnimation') add_library('peasycam') GRID_SIZE = 32 -SKETCH_NAME = "s218" +SKETCH_NAME = "s217" OUTPUT = ".gif" -nodes = [] -node_grid = dict() - -Node = namedtuple('node', ['x', 'y', 'z', 'cor', 'size']) - def setup(): print_text_for_readme(SKETCH_NAME, OUTPUT) - global border, spacing - size(700, 700, P3D) + colorMode(HSB) # hint(ENABLE_DEPTH_SORT) # optional PeasyCam setup to allow orbiting with a mouse drag cam = PeasyCam(this, 100) cam.setMinimumDistance(1000) cam.setMaximumDistance(1000) # sets border and grid spacing - border = 50 - spacing = (width - border * 2) / GRID_SIZE + Node.border = 50 + Node.spacing = (width - Node.border * 2) / GRID_SIZE - # nodes is a list of nodes in a 3D grid + # Node.nodes is a list of nodes in a 3D grid for x in range(GRID_SIZE): for y in range(GRID_SIZE): for z in range(GRID_SIZE): - set_node(x, y, z) + new_node = Node(x, y, z) + Node.nodes.append(new_node) + Node.grid[x, y, z] = new_node m = GRID_SIZE - 1 - for s in range(GRID_SIZE): - node_grid[(0, 0, s)].cor = color(255, 0, 0) - node_grid[(0, s, 0)].cor = color(0, 0, 255) - node_grid[(s, 0, 0)].cor = color(0, 255, 0) - node_grid[(m, m, s)].cor = color(255, 0, 0) - node_grid[(m, s, m)].cor = color(0, 0, 255) - node_grid[(s, m, m)].cor = color(0, 255, 0) - node_grid[(0, m, s)].cor = color(255, 0, 0) - node_grid[(0, s, m)].cor = color(0, 0, 255) - node_grid[(s, 0, m)].cor = color(0, 255, 0) - node_grid[(m, 0, s)].cor = color(255, 0, 0) - node_grid[(m, s, 0)].cor = color(0, 0, 255) - node_grid[(s, m, 0)].cor = color(0, 255, 0) - for i in range(1, 50): - c = 255 if i < 25 else None + # for s in range(GRID_SIZE): + # Node.grid[(0, 0, s)].cor = color(255, 0, 0) + # Node.grid[(0, s, 0)].cor = color(0, 0, 255) + # Node.grid[(s, 0, 0)].cor = color(0, 255, 0) + # Node.grid[(m, m, s)].cor = color(255, 0, 0) + # Node.grid[(m, s, m)].cor = color(0, 0, 255) + # Node.grid[(s, m, m)].cor = color(0, 255, 0) + # Node.grid[(0, m, s)].cor = color(255, 0, 0) + # Node.grid[(0, s, m)].cor = color(0, 0, 255) + # Node.grid[(s, 0, m)].cor = color(0, 255, 0) + # Node.grid[(m, 0, s)].cor = color(255, 0, 0) + # Node.grid[(m, s, 0)].cor = color(0, 0, 255) + # Node.grid[(s, m, 0)].cor = color(0, 255, 0) + box_list = [] + num_boxes = 64 + for i in range(num_boxes): x = randint(1, m) - 1 y = randint(1, m) - 1 z = randint(1, m) - 1 w = randint(1, m - x + 1) - 1 h = randint(1, m - y + 1) - 1 d = randint(1, m - z + 1) - 1 - big_box(x, y, z, w, h, d, c) + box_list.append((x, y, z, w, h, d)) + for i in range(num_boxes): + x, y, z, w, h, d = box_list[i] + big_box(x, y, z, w, h, d, color(i*4, 255, 255)) + for i in range(num_boxes): + x, y, z, w, h, d = box_list[i] + side = randint(1, 3) + if side == 1: + h -= 1 + w -= 1 + elif side == 2: + d -= 1 + h -= 1 + else: + w -= 1 + d -= 1 + big_box(x, y, z, w, h, d, None) def draw(): @@ -67,7 +79,7 @@ def draw(): rotate(-1 + TWO_PI / (GRID_SIZE * 2) * frameCount, 1 / 2, 1, 1 / 2) background(100) - for node in nodes: + for node in Node.nodes: node.plot() if frameCount < GRID_SIZE * 2: @@ -85,31 +97,31 @@ def big_box(px, py, pz, w, h=None, d=None, c=255): if (0 <= x < GRID_SIZE and 0 <= y < GRID_SIZE and 0 <= z < GRID_SIZE): - node_grid[(x, y, z)].cor = c + Node.grid[(x, y, z)].cor = c -def set_node(x, y, z, s=1, c=None): - new_node = Node( - border + spacing / 2 + x * spacing - width / 2, - border + spacing / 2 + y * spacing - width / 2, - border + spacing / 2 + z * spacing - width / 2, - s, # size - c, # color - ) - if (x, y, z) not in grid_nodes: - nodes.append(new_node) - # pensar em como remover os Vazios. - grid_nodes[x, y, z] = new_node +class Node(): + nodes = [] + grid = dict() -def plot(): - # """ draws box """ - for n in nodes: - if n.cor: - noStroke() # stroke(0) - fill(n.cor) - with pushMatrix(): - translate(n.x, n.y, n.z) - box(spacing * n.s) + def __init__(self, x, y, z): + self.ix = x + self.iy = y + self.iz = z + self.x = Node.border + Node.spacing / 2 + x * Node.spacing - width / 2 + self.y = Node.border + Node.spacing / 2 + y * Node.spacing - width / 2 + self.z = Node.border + Node.spacing / 2 + z * Node.spacing - width / 2 + self.size_ = 1 + self.cor = None + + def plot(self): + """ draws box """ + if self.cor: + # noStroke() # stroke(0) + fill(self.cor) + with pushMatrix(): + translate(self.x, self.y, self.z) + box(Node.spacing * self.size_) def keyPressed(): diff --git a/s218/s218b.gif b/s218/s218b.gif new file mode 100644 index 00000000..79dba550 Binary files /dev/null and b/s218/s218b.gif differ