morphing.py

Created by schraf

Created on May 14, 2024

714 Bytes


import turtle

t = turtle
# figure départ
dep = (5,200),(5,150),(15,150),(15,170),(35,170),(35,150),(46,150),(46,200),(35,200),(35,180),(15,180),(15,200),(5,200)
# figure arrivée
arr = (270,68),(270,18),(310,18),(310,27),(280,27),(280,40),(310,40),(310,48),(280,48),(280,60),(310,60),(310,68),(270,68)
# nb d'étapes
n = 6

# position du point n°k à la e-ième étape
def pt(k, e, xy): return ((n - e) * dep[k][xy] + e * arr[k][xy]) / n

def etape(k, e): return (-160 + pt(k, e, 0), -110 + pt(k, e, 1))

# pour chacune des étapes
for e in range(n + 1):
 t.penup()
 # représenter la figure
 for k in range(len(dep)):
  # composée de segments
  t.goto(etape(k, e))
  t.pendown()

t.hideturtle()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.