Os exemplos mais abaixo neste Gist são a inspiração para 3 videozinhos sobre Azulejos de Truchet com py5 (usando py5 imported mode no Thonny)
- 1 https://peertube.lhc.net.br/w/umbmBicMFuUVKDD6gpnWpM
- 2 https://peertube.lhc.net.br/w/9wiWAvqigruASr3Kj4F7id
- 3 https://peertube.lhc.net.br/w/in7VefyJJAwcEcKfwDerts
Se você gostar, considere apoiar a instância do PeerTube do LHC que hospeda os vídeos https://peertube.lhc.net.br e me apoiar (que fiz esse material) https://liberapay.com/villares
COLS = FILS = 10
def setup():
size(800, 800)
rect_mode(CENTER) # retângulos pelo centro
# width é automático e vem do size
# size(800, 800) -> width 800 height 800
tam = width / COLS
for fila in range(FILS):
y = tam / 2 + tam * fila
for coluna in range(COLS):
x = tam / 2 + tam * coluna
square(x, y, tam)
Exemplo azulejo tosco mas que gira
def setup():
size(800, 800)
rect_mode(CENTER)
def draw():
background(0, 0, 100)
angulo = radians(mouse_x) # angulo em radianos
print(mouse_x, angulo)
azulejo(150, 150, 200, angulo)
azulejo(150+200, 150, 200, angulo)
def azulejo(x, y, tam, rot):
push_matrix() # guarda coordenadas atuais
translate(x, y) # muda o 0, 0
rotate(rot)
fill(255)
square(0, 0, tam)
fill(0)
square(tam / 4, tam / 4, tam / 4)
pop_matrix() # volta coordenadas anteriores
Primeiro exemplo com azulejo truchet e regra de girar 90
COLS = FILS = 10
def setup():
size(800, 800)
rect_mode(CENTER) # retângulos pelo centro
# width é automático e vem do size
# size(800, 800) -> width 800 height 800
def draw():
if is_key_pressed:
stroke(255, 0, 0)
else:
no_stroke()
tam = width / COLS
angulo = 0
for fila in range(FILS):
y = tam / 2 + tam * fila
for coluna in range(COLS):
x = tam / 2 + tam * coluna
azulejo(x, y, tam, radians(angulo))
angulo = angulo + 90
def azulejo(x, y, tam, rot):
push_matrix() # guarda coordenadas atuais
translate(x, y) # muda o 0, 0
rotate(rot)
fill(255)
square(0, 0, tam)
fill(0)
triangle(tam / 2, -tam / 2,
tam / 2, tam / 2,
-tam / 2, tam / 2)
pop_matrix() # volta coordenadas anteriores
Outra regra
COLS = FILS = 10
def setup():
size(800, 800)
rect_mode(CENTER) # retângulos pelo centro
def draw():
if is_key_pressed():
stroke(255, 0, 0)
else:
no_stroke()
tam = width / COLS
angulo = 0
for fila in range(FILS):
y = tam / 2 + tam * fila
for coluna in range(COLS):
x = tam / 2 + tam * coluna
if fila % 2 == 0:
angulo = 0
else:
angulo = 90
if coluna % 2 == 0:
angulo = angulo + 90
azulejo(x, y, tam, radians(angulo))
def azulejo(x, y, tam, rot):
push_matrix() # guarda coordenadas atuais
translate(x, y) # muda o 0, 0
rotate(rot)
fill(255)
square(0, 0, tam)
fill(0)
triangle(tam / 2, -tam / 2,
tam / 2, tam / 2,
-tam / 2, tam / 2)
pop_matrix() # volta coordenadas anteriores