Skip to content

Instantly share code, notes, and snippets.

@villares
Last active March 12, 2024 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save villares/b596399b098ea0ebeb8e2d4ad0662df8 to your computer and use it in GitHub Desktop.
Save villares/b596399b098ea0ebeb8e2d4ad0662df8 to your computer and use it in GitHub Desktop.
Elementos para criar Truchet Tiles https://en.wikipedia.org/wiki/Truchet_tiles com py5 #Truchet #Pyhon #py5 #ProgramaçãoCriativa

Truchet tiles

Vídeos

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)

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

Mais exemplos

Exemplo de grade com 10 x 10 elementos

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)    
        

image


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

image


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

image


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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment