frises.py

Created by schraf

Created on February 25, 2022

761 Bytes

>> frise(f1) pour afficher la première frise, >> frise(f2,4) pour affiche la frise n°2 en petit, >> frise(f3,16) pour affiche la frise n°3 en grand, etc.


import turtle
turtle.speed(0)

f1 = [(0,0),(0,1),(1,2),(2,2),(2,1),(1,0),(1,1),(0,1),0,(0,0),(1,0),0,(2,0)]
f2 = [(0,1),(0,2),(3,2),(3,1),(2,0),(1,0),(0,1),0,(0,2),(1,1),(1,0),(2,0),(2,1),(1,1),0,(2,1),(3,2)]
f3 = [(0,0),(0,1),(1,2),(2,2),(1,1),(0,1),0,(0,0),(1,0),(1,1),(1,0),(2,2),(3,0),(3,1),(2,2),(3,2),(4,1),(3,1),0,(3,0),(4,0),(4,1)]
f4 = [(0,1),(1,2),(3,2),(2,0),(2,1),(3,2),0,(2,0),(0,0),(0,1),(2,1),0,(3,0)]

def frise(f, d = 8):
  y = 110 - 2 * d
  while y >= -110:
   turtle.penup()
   x = -160
   turtle.goto(x,y)
   while x < 160:
    for v in f:
     if v == 0: turtle.penup()
     else: 
      px = x + d * v[0]
      py = y + d * v[1]
      turtle.goto(px, py)
      turtle.pendown()
    x = px
   y -= 3 * d
  turtle.hideturtle()