sketch-a-day/2019/sketch_191017a/sketch_191017a.pyde

56 wiersze
1.4 KiB
Plaintext
Czysty Zwykły widok Historia

2019-10-18 02:40:09 +00:00
from random import choice
def setup():
size(600, 600)
noLoop()
rectMode(CENTER)
strokeJoin(ROUND)
def draw():
2019-10-18 02:41:22 +00:00
background(100)
grid(width / 2, width / 2, 4, width)
2019-10-18 02:40:09 +00:00
2019-10-18 02:41:22 +00:00
def grid(xo, yo, n, tw, e=None):
2019-10-18 02:40:09 +00:00
"""
2019-10-18 02:41:22 +00:00
Faça o desenho do grid baseado em uma subdivisão (grade) recursiva
2019-10-18 02:40:09 +00:00
"""
cw = tw / n
offset = (cw - tw) / 2.
for i in range(n):
x = xo + offset + cw * i
for j in range(n):
y = yo + offset + cw * j
2019-10-18 02:41:22 +00:00
if cw > 30 and random(10) < 8: # faz subdivisão recursiva
grid(x, y, 3, cw)
2019-10-18 02:40:09 +00:00
else: # faz um elemento "sozinho"
2019-10-18 02:41:22 +00:00
poly_arrow(x, y, cw, i, j)
2019-10-18 02:40:09 +00:00
2019-10-18 02:41:22 +00:00
def poly_arrow(x, y, s, i, j):
w = s / (1 + i) # x / s)
h = s / (1 + j ) # y / s)
2019-10-18 02:40:09 +00:00
""" Seta na posição x, y com largura w e altura h"""
2019-10-18 02:41:22 +00:00
mw = w
mh = h
2019-10-18 02:40:09 +00:00
pushMatrix() # preserva o sistema de coordenadas atual
translate(x, y) # translada a origem do sistema de coordenadas
r = choice((0, 1, 2, 4))
rotate(r * HALF_PI)
beginShape() # começa a desenhar a forma, inicia um polígono
vertex(0, -0 - mw)
vertex(-mw , 0)
vertex(-mw, mh)
vertex(0, mh - mw)
vertex(mw, mh)
vertex(mw, 0)
# vertex(0, 0)
endShape(CLOSE) # encerra a forma a fechando no primeiro vértice
popMatrix() # retorna o sistema de coordenadas anterior
def keyPressed():
if key == 's':
saveFrame("####.png")
redraw()