Code:
# 20/11/2024
from random import*
def t1(x,y,r,g,b):
A = Point(x,y,is_visible = False)
B = Point(x,y+1,is_visible = False)
C = Point(x+1,y+1,is_visible = False)
p = Polygon([A,B,C],color=[r,g,b],opacity=1,line_thickness=0)
def t2(x,y,r,g,b):
D = Point(x+1,y,is_visible = False)
B = Point(x,y+1,is_visible = False)
C = Point(x+1,y+1,is_visible = False)
p = Polygon([B,C,D],color=[r,g,b],opacity=1,line_thickness=0)
def t3(x,y,r,g,b):
C = Point(x+1,y+1,is_visible = False)
D = Point(x+1,y,is_visible = False)
A = Point(x,y,is_visible = False)
p = Polygon([C,D,A],color=[r,g,b],opacity=1,line_thickness=0)
def t4(x,y,r,g,b):
D = Point(x+1,y,is_visible = False)
A = Point(x,y,is_visible = False)
B = Point(x,y+1,is_visible = False)
p = Polygon([D,A,B],color=[r,g,b],opacity=1,line_thickness=0)
def dessin(n):
for y in range(n):
for x in range(n):
a = randint(1,4)
if a==1:
t1(x,y,0,0,0)
t2(-x-1,y,0,0,0)
t4(x,-y-1,0,0,0)
t3(-x-1,-y-1,0,0,0)
if a==2:
t2(x,y,0,0,0)
t1(-x-1,y,0,0,0)
t3(x,-y-1,0,0,0)
t4(-x-1,-y-1,0,0,0)
if a==3:
t3(x,y,0,0,0)
t4(-x-1,y,0,0,0)
t2(x,-y-1,0,0,0)
t1(-x-1,-y-1,0,0,0)
if a==4:
t4(x,y,0,0,0)
t3(-x-1,y,0,0,0)
t1(x,-y-1,0,0,0)
t2(-x-1,-y-1,0,0,0)
################### Exécution ##########################
n = 5
fond = Polygon(Point(-n-1,-n-1,is_visible=False),Point(n+1,-n-1,is_visible=False),4
,opacity=1,color="white",line_thickness=0)
dessin(n)