Code
#03/02/2024
#grille formés de façon aléatoire par des triangles de cotés 1,2 ou3.
from random import*
import time
def maximum(liste):
maxi = liste[0]
for i in liste:
if i >= maxi:
maxi = i
return maxi
def triangle(x,y,taille):
r = randint(1,4)
if r ==1:
A = Point(x,y,is_visible=False)
B = Point(x+taille,y,is_visible=False)
C = Point(x+taille,y+taille,is_visible=False)
D = Point(x,y+taille,is_visible=False)
T = Polygon([A,B,C])
T2 = Polygon([A,D,C])
if r ==2:
A = Point(x,y,is_visible=False)
B = Point(x+taille,y,is_visible=False)
C = Point(x+taille,y+taille,is_visible=False)
D = Point(x,y+taille,is_visible=False)
T=Polygon([B,C,D])
T2=Polygon([D,A,B])
if r ==3:
A = Point(x,y,is_visible=False)
B = Point(x+taille,y,is_visible=False)
C = Point(x+taille,y+taille,is_visible=False)
D = Point(x,y+taille,is_visible=False)
T=Polygon([C,D,A])
T2=Polygon([A,B,C])
if r ==4:
A = Point(x,y,is_visible=False)
B = Point(x+taille,y,is_visible=False)
C = Point(x+taille,y+taille,is_visible=False)
D = Point(x,y+taille,is_visible=False)
T=Polygon([D,A,B])
T2=Polygon([B,C,D])
T.opacity=1
T.color=[0,1,1]
T.line_thickness=0
T2.opacity=1
T2.color=[1,0,0]
T2.line_thickness=0
t=0.01
x = 0
y = 0
xmax = 21
ymax = 20
p = [2,2,1]
fond=Polygon(Point(-6,-6,is_visible=False),Point(xmax+6,-6,is_visible=False),4)
fond.color="black"
fond.opacity=1
fond.line_thickness=0
while y<ymax:
total = 0
x = 0
l = []
while total<xmax:
r = choice(p)
if total==xmax-1:
total=total+1
r=1
elif total==xmax-2:
rr = randint(1,2)
total=total+rr
r= rr
elif total==xmax-3:
rr = randint(1,3)
total=total+rr
r =rr
else:
total=total+r
l.append(r)
hauteur=maximum(l)
print(l)
for a in range(len(l)):
if l[a]==1:
for i in range(0,hauteur):
triangle(x,y+i,1)
time.sleep(t)
if l[a]==2:
if hauteur<=2:
triangle(x,y,2)
time.sleep(t)
else:
triangle(x,y,2)
time.sleep(t)
triangle(x,y+2,1)
time.sleep(t)
triangle(x+1,y+2,1)
time.sleep(t)
if l[a]==3:
triangle(x,y,3)
time.sleep(t)
x = x+ l[a]
y = y+hauteur