carres_imbriques.py

Created by elodie-gamot

Created on March 16, 2022

948 Bytes

Figure 1 : cas simple où l’on positionne le début du second carré à 50% de la longueur initiale. Figure 2 : cas simple à 25% de la longueur initiale avec utilisation des relations trigonométriques. Figure 3 : cas général avec a variable.


from math import *
from turtle import *

def carre(l):
  for i in range(4):
    forward(l)
    right(90)
  
def figure(l,n):
  penup()
  goto(-50,50)
  pendown()
  for i in range(n):
    carre(l)
    forward(l*0.5)
    right(45)
    l=sqrt((l**2)/2)
    
def figure2(l,n):
  penup()
  goto(-50,50)
  pendown()
  for i in range(n):
    carre(l)
    forward(l*0.25)
    angle=atan(1/3)*180/pi
    right(angle)
    l=sqrt((0.75*l)**2+(0.25*l)**2)

def figure3(l,n,a):
  penup()
  goto(-50,50)
  pendown()
  for i in range(n):
    carre(l)
    forward(l*a)
    angle=atan(a/(1-a))*180/pi
    right(angle)
    l=sqrt(((1-a)*l)**2+(a*l)**2)
    
def variante(l,a):
  penup()
  x=-160+((320-l)/2)
  y=111-((222-l)/2)
  goto(x,y)
  pendown()
  color(0,255,255)
  #color(255,166,163)
  while l>5:
    color(l,255-l,255-l)
    carre(l)
    forward(l*a)
    angle=atan(a/(1-a))*180/pi
    right(angle)
    l=sqrt(((1-a)*l)**2+(a*l)**2)

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>.