Alexandre B A Villares 2018-10-09 23:59:36 -03:00
rodzic 343d42ad9a
commit 1e2fc9d3ea
3 zmienionych plików z 161 dodań i 0 usunięć

BIN
s284/2621.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 30 KiB

68
s284/node.py 100644
Wyświetl plik

@ -0,0 +1,68 @@
class Node():
nodes = []
grid = dict()
ver = set()
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
self.nb = {0 : False, # |* left
1 : False, # *| right
2 : False, # - top
3 : False, # _ bottom
4 : False,
5 : False,
}
self.borders = []
def plot(self):
""" draws node """
if self.cor:
noFill() #stroke(0)
stroke(self.cor)
with pushMatrix():
translate(0, 0, self.z)
#rect(0, 0, Node.spacing * self.size_, Node.spacing * self.size_)
self.draw_borders()
def draw_borders(self):
if self.borders:
for x1, y1, x2, y2 in self.borders:
line(x1, y1, x2, y2)
def update_borders(self):
b = self.borders
w = h = Node.spacing * self.size_
tlX, tlY = self.x - w/2, self.y - h/2
trX, trY = self.x + w/2, self.y - h/2
blX, blY = self.x - w/2, self.y + h/2
brX, brY = self.x + w/2, self.y + h/2
if not self.nb[0]: b.append((tlX, tlY, blX, blY))
if not self.nb[1]: b.append((trX, trY, brX, brY))
if not self.nb[2]: b.append((tlX, tlY, trX, trY))
if not self.nb[3]: b.append((blX, blY, brX, brY))
def update_nbs(self):
nb0 = Node.grid.get((self.ix-1, self.iy, self.iz))
self.nb[0] = True if nb0 and nb0.cor else False
nb1 = Node.grid.get((self.ix+1, self.iy, self.iz))
self.nb[1] = True if nb1 and nb1.cor else False
nb2 = Node.grid.get((self.ix, self.iy-1, self.iz))
self.nb[2] = True if nb2 and nb2.cor else False
nb3 = Node.grid.get((self.ix, self.iy+1, self.iz))
self.nb[3] = True if nb3 and nb3.cor else False
nb4 = Node.grid.get((self.ix, self.iy, self.iz-1))
self.nb[4] = True if nb4 and nb4.cor else False
nb5 = Node.grid.get((self.ix, self.iy, self.iz+1))
self.nb[5] = True if nb5 and nb5.cor else False
self.update_borders()

93
s284/s284.pyde 100644
Wyświetl plik

@ -0,0 +1,93 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME = "s284" # 2018109
OUTPUT = ".gif"
GRID_SIZE = 6
add_library('peasycam')
from random import seed
from random import choice
from random import randint
from node import Node
def setup():
global ang
ang = 0
size(500, 500, P3D)
colorMode(HSB)
strokeWeight(2)
cam = PeasyCam(this, 100)
cam.setMinimumDistance(750)
cam.setMaximumDistance(750)
random_seed(101)
init_grid(GRID_SIZE)
def draw():
global ang
background(0)
rotateY(ang)
for node in Node.nodes:
node.plot()
for l in range(GRID_SIZE):
beginShape()
for x, y, z, iz in Node.ver:
if l == iz:
vertex(x, y, z+1)
endShape()
if ang <= TWO_PI:
#saveFrame("###.png")
ang += 0.02
def init_grid(grid_size):
Node.border = 10
Node.spacing = (width - Node.border * 2) / grid_size
Node.nodes = []
Node.ver = []
for x in range(grid_size):
for y in range(grid_size):
for z in range(grid_size):
new_node = Node(x, y, z)
Node.nodes.append(new_node)
Node.grid[x, y, z] = new_node
if randint(1, 10) > 5:
new_node.cor = color(z * 28, 255, 255)
else:
new_node.cor = None
for node in Node.nodes:
node.update_nbs()
for node in Node.nodes:
for x1, y1, x2, y2 in node.borders:
Node.ver.append((x1, y1, node.z, node.iz))
Node.ver.append((x2, y2, node.z, node.iz))
def keyPressed():
if key == "n":
init_grid(GRID_SIZE)
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)
)