# 12/12/2024
# Un pavage (ou motif) de Truchet étendu.
from random import*
from math import*
# les 2 types de tuiles
# avec du bleu dans le coin supérieur gauche et le coin inférieur droit:
def t11(x,y):
A = Point(x,y,is_visible = False)
B = Point(x+1,y,is_visible = False)
C = Point(x+1,y+1,is_visible = False)
D = Point(x,y+1,is_visible = False)
E = Point(x+0.5,y,is_visible = False)
F = Point(x+1,y+0.5,is_visible = False)
G = Point(x+0.5,y+1,is_visible = False)
H = Point(x,y+0.5,is_visible = False)
p1 = Polygon([A,E,F,C,G,H],color="yellow",opacity=1,line_thickness=0)
p2 = Polygon([E,B,F],color="blue",opacity=1,line_thickness=0)
p3 = Polygon([H,G,D],color="blue",opacity=1,line_thickness=0)
def t12(x,y):
A = Point(x,y,is_visible = False)
B = Point(x+1,y,is_visible = False)
C = Point(x+1,y+1,is_visible = False)
D = Point(x,y+1,is_visible = False)
E = Point(x+0.5,y,is_visible = False)
F = Point(x+1,y+0.5,is_visible = False)
G = Point(x+0.5,y+1,is_visible = False)
H = Point(x,y+0.5,is_visible = False)
p1 = Polygon([E,B,F,G,D,H],color="blue",opacity=1,line_thickness=0)
p2 = Polygon([A,E,H],color="yellow",opacity=1,line_thickness=0)
p3 = Polygon([F,G,C],color="yellow",opacity=1,line_thickness=0)
# les 2 types de tuiles
# avec du jaune dans le coin supérieur gauche et le coin inférieur droit:
def t21(x,y):
A = Point(x,y,is_visible = False)
B = Point(x+1,y,is_visible = False)
C = Point(x+1,y+1,is_visible = False)
D = Point(x,y+1,is_visible = False)
E = Point(x+0.5,y,is_visible = False)
F = Point(x+1,y+0.5,is_visible = False)
G = Point(x+0.5,y+1,is_visible = False)
H = Point(x,y+0.5,is_visible = False)
p1 = Polygon([A,E,F,C,G,H],color="blue",opacity=1,line_thickness=0)
p2 = Polygon([E,B,F],color="yellow",opacity=1,line_thickness=0)
p3 = Polygon([H,G,D],color="yellow",opacity=1,line_thickness=0)
def t22(x,y):
A = Point(x,y,is_visible = False)
B = Point(x+1,y,is_visible = False)
C = Point(x+1,y+1,is_visible = False)
D = Point(x,y+1,is_visible = False)
E = Point(x+0.5,y,is_visible = False)
F = Point(x+1,y+0.5,is_visible = False)
G = Point(x+0.5,y+1,is_visible = False)
H = Point(x,y+0.5,is_visible = False)
p1 = Polygon([E,B,F,G,D,H],color="yellow",opacity=1,line_thickness=0)
p2 = Polygon([A,E,H],color="blue",opacity=1,line_thickness=0)
p3 = Polygon([F,G,C],color="blue",opacity=1,line_thickness=0)
# Dessin du motif
def dessin(n):
for y in range(n):
for x in range(n):
a = randint(1,2)
if (x+y)%2==0:
if a==1:
t11(x,y)
else:
t12(x,y)
else:
if a==1:
t21(x,y)
else:
t22(x,y)
################### Exécution ##########################
n = 10 # nombre de lignes et de colonnes
fond = Polygon(Point(-1,-1,is_visible=False),Point(n+1,-1,is_visible=False),4
,opacity=1,color="white",line_thickness=0)
dessin(n)