arbre.py

Created by cent20

Created on September 22, 2021

1.13 KB

Réalisé par une élève de seconde dans le cadre d’un DM


# Auteur : Jade C.
# Réalisé par une de mes élèves de seconde 
# dans le cadre d'un DM "Les mathématiques sont belles"
# https://twitter.com/nsi_xyz/status/1380526928671674373

# Arbre de pythagore https://fr.wikipedia.org/wiki/Arbre_de_Pythagore

from turtle import *
from kandinsky import*
from random import *
fill_rect(0,0,400,400,color(210,210,210))
f=0
pensize(20)
penup()
goto(-160,-100)
pendown()
pencolor(255,255,255)
goto(160,-100)
pensize(5)
while f<=50:
  penup()
  goto(randint(-160,160),randint(-120,120))
  pendown()
  pencolor(255,255,255)
  for i in range(5):
    circle(i)
  f=f+1

speed(11)
hideturtle()


angle=50
pencolor(165,42,42)

def arbre(n,longueur):
  if n==0 :
    pencolor(255,140,0)
    forward(longueur)
    backward(longueur)
    pencolor(165,42,42)
  else:
    width(n)
    forward(longueur/3)
    left(angle)
    arbre(n-1,longueur*2/3)
    right(2*angle)
    arbre(n-1,longueur*2/3)
    left(angle)
    backward(longueur/3)
    
hideturtle()
penup();right(90);
forward(200)
left(200)
pendown()
goto(0,-120)
setheading(90)
arbre(11,200)
penup()
goto(100,100)
pendown()

        
showturtle()
mainloop()

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