Un pavage de Truchet étendu généré avec #pyggb variante

Image
 # 12/12/2024 # Un pavage (ou motif) de Truchet étendu. Variante avec des lignes polygonales # aléatoires. from random import* import time nbp=0 # fonction ligne polygonale déformée de façon aléatoire def liste(P,Q,R,n): r = random()/10 p = randint(1,2) L=[] vx=Q.x-P.x vy=Q.y-P.y L.append(P) for i in range(1,n): L.append(Point(P.x+i/n * vx+(-1)**p*r*random(),P.y+i/n * vy+(-1)**p*r*random(),is_visible=False)) L.append(Q) L.append(R) return L # fonction ligne brisée . En entrée une liste L de points. def ligneb(L): for i in range(len(L)-1): s =Segment(L[i],L[i+1]) # 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) L1 = liste(E,F,B,nbp) L2 = liste(H,G,D,nbp) p2 = Polygon(L1,color="blue",opacity=1,line_thickness=0) p3 = Polygon(L2,color="blue",opacity=1,line_thickness=0) del L1[-1] del L2[-1] L1.append(C) L2.reverse() L2.append(A) L= L2+L1 p1 = Polygon(L,color="yellow",opacity=1,line_thickness=0) del L1[-1] del L2[-1] ligneb(L1) ligneb(L2) 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) L1 = liste(H,E,A,nbp) L2 = liste(F,G,C,nbp) p2 = Polygon(L1,color="yellow",opacity=1,line_thickness=0) p3 = Polygon(L2,color="yellow",opacity=1,line_thickness=0) del L1[-1] del L2[-1] L1.append(B) L2.append(D) L= L2+L1 p1 = Polygon(L,color="blue",opacity=1,line_thickness=0) del L1[-1] del L2[-1] ligneb(L1) ligneb(L2) # 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) L1 = liste(E,F,B,nbp) L2 = liste(H,G,D,nbp) p2 = Polygon(L1,color="yellow",opacity=1,line_thickness=0) p3 = Polygon(L2,color="yellow",opacity=1,line_thickness=0) del L1[-1] del L2[-1] L1.append(C) L2.reverse() L2.append(A) L= L2+L1 p1 = Polygon(L,color="blue",opacity=1,line_thickness=0) del L1[-1] del L2[-1] ligneb(L1) ligneb(L2) 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) L1 = liste(H,E,A,nbp) L2 = liste(F,G,C,nbp) p2 = Polygon(L1,color="blue",opacity=1,line_thickness=0) p3 = Polygon(L2,color="blue",opacity=1,line_thickness=0) del L1[-1] del L2[-1] L1.append(B) L2.append(D) L= L2+L1 p1 = Polygon(L,color="yellow",opacity=1,line_thickness=0) del L1[-1] del L2[-1] ligneb(L1) ligneb(L2) #bordure def b11(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) L1 = liste(E,F,B,nbp) L2 = liste(H,G,D,nbp) #p2 = Polygon(L1,color="blue",opacity=1,line_thickness=0) p3 = Polygon(L2,color="yellow",opacity=1,line_thickness=0) #del L1[-1] del L2[-1] ligneb(L2) #L1.append(C) L2.append(C) L2.append(B) L2.append(A) #L= L2+L1 p1 = Polygon(L2,color="blue",opacity=1,line_thickness=0) def b12(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) L1 = liste(H,E,A,nbp) L2 = liste(F,G,C,nbp) #p2 = Polygon(L1,color="blue",opacity=1,line_thickness=0) p3 = Polygon(L2,color="yellow",opacity=1,line_thickness=0) #del L1[-1] del L2[-1] ligneb(L2) L2.append(D) L2.append(A) L2.append(B) p1 = Polygon(L2,color="blue",opacity=1,line_thickness=0) def b21(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) L1 = liste(E,F,B,nbp) #L2 = liste(H,G,D,nbp) p2 = Polygon(L1,color="yellow",opacity=1,line_thickness=0) #p3 = Polygon(L2,color="yellow",opacity=1,line_thickness=0) del L1[-1] ligneb(L1) #L1.append(C) L1.append(C) L1.append(D) L1.append(A) #L= L2+L1 p1 = Polygon(L1,color="blue",opacity=1,line_thickness=0) def b22(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) L1 = liste(H,E,A,nbp) #L2 = liste(F,G,C,nbp) p2 = Polygon(L1,color="yellow",opacity=1,line_thickness=0) #p3 = Polygon(L2,color="yellow",opacity=1,line_thickness=0) #del L1[-1] del L1[-1] ligneb(L1) L1.append(B) L1.append(C) L1.append(D) p1 = Polygon(L1,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) #global nbp #nbp = x 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) time.sleep(0.01) ################### Exécution ########################## nbp = 3 # nombre de points des lignes polygonales/brisées n = 8 # nombre de lignes et de colonnes, nombre entier PAIR fond = Polygon(Point(-2,-2,is_visible=False),Point(n+2,-2,is_visible=False),4 ,opacity=1,color="white",line_thickness=0) dessin(n) #bordure( bug pour n impair !) : for i in range(0,n,2): b11(i,-1) time.sleep(0.01) for i in range(1,n,2): b12(i,-1) time.sleep(0.01) for i in range(-1,n,2): b11(n,i) time.sleep(0.01) for i in range(-1,n,2): b12(-1,i) time.sleep(0.01) for i in range(0,n,2): b21(-1,i) time.sleep(0.01) for i in range(-1,n,2): b21(i,n) time.sleep(0.01) for i in range(0,n,2): b22(i,n) time.sleep(0.01) for i in range(0,n+1,2): b22(n,i) time.sleep(0.01)
Image
Image