sketch-a-day/2018/s180108/s180108.pyde

49 wiersze
1.5 KiB
Plaintext
Czysty Zwykły widok Historia

2018-01-09 21:26:01 +00:00
"""
s180108 Platonic Solid Grid in Processing.Py
(c)2018 Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
"""
2018-01-08 16:26:25 +00:00
from PlatonicSolids import *
NUM_COLS, NUM_ROWS = 5, 5
NUM_CELLS = NUM_COLS * NUM_ROWS
solids = []
r_x = 0
r_y = 0
def setup():
global CELL_SIZE
size(500, 500, P3D)
CELL_SIZE = width / NUM_COLS
strokeWeight(5)
noFill()
colorMode(HSB)
for i in range(NUM_CELLS):
2018-01-09 02:53:50 +00:00
s = PlatonicFactory(int(random(5))) # Instancia aleatoriamente um dos sólidos
2018-01-08 16:26:25 +00:00
c = color(random(256), 200, 200, 128) # random HSB translucent colors
2018-01-09 21:26:01 +00:00
s.c = c # Tasca cor no sólido, vou usar no loop do draw!
2018-01-08 19:00:00 +00:00
solids.append(s)
2018-01-08 16:26:25 +00:00
def draw():
global r_x, r_y
# translate(-width/2, -height/2) # may need to use with PeasyCam
r_x += 0.02 # x rotation speed
r_y += 0.01 # y rotation speed
background(255) # clear frame with white
2018-01-09 02:53:50 +00:00
# lights() # use this if you use filled faces
2018-01-08 16:26:25 +00:00
for i in range(NUM_CELLS):
x, y = x_y_from_i(i, NUM_COLS, NUM_ROWS)
cx, cy = CELL_SIZE / 2 + x * CELL_SIZE, CELL_SIZE / 2 + y * CELL_SIZE
with pushMatrix():
d = dist(mouseX, mouseY, cx, cy)
translate(cx, cy)
2018-01-09 21:26:01 +00:00
if d < 80: # se o mouse está perto, gira!
2018-01-08 16:26:25 +00:00
rotateX(r_y)
rotateY(r_x)
2018-01-09 21:26:01 +00:00
stroke(solids[i].c) # Lembrando que de fábrica não tem .c
2018-01-08 19:00:00 +00:00
solids[i].create()
2018-01-09 21:26:01 +00:00
# if (frameCount < 200): saveFrame("###.tga") # para salvar frames
2018-01-08 16:26:25 +00:00
def x_y_from_i(i, max_x, max_y):
2018-01-09 21:26:01 +00:00
return i % max_x, (i / max_x) % max_y