-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharbre_de_pythagore.py
More file actions
50 lines (41 loc) · 911 Bytes
/
arbre_de_pythagore.py
File metadata and controls
50 lines (41 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: UTF-8 -*-
import turtle
t = turtle.Pen()
# ½√2
FACTEUR = 0.7071067811865476
def couleur(ordre):
teinte = (1.0/(ordre+1.5))
return (teinte*0.5, teinte, teinte*0.5)
def arbre_de_pythagore(t, longueur_cote, ordre):
couleur_actuelle = t.pencolor()
t.pencolor(couleur(ordre))
t.forward(longueur_cote)
if ordre > 0:
l = longueur_cote*FACTEUR
t.right(45)
arbre_de_pythagore(t, l, ordre-1)
t.left(45)
t.left(90)
t.forward(longueur_cote)
if ordre > 0:
l = longueur_cote*FACTEUR
t.right(135)
t.penup()
t.forward(l)
t.pendown()
t.left(90)
arbre_de_pythagore(t, l, ordre-1)
t.right(90)
t.backward(l)
t.left(135)
t.left(90)
t.forward(longueur_cote)
t.left(90)
t.forward(longueur_cote)
t.left(90)
t.pencolor(couleur_actuelle)
t.speed("fastest")
t.left(90)
arbre_de_pythagore(t, 100, 7)
t.hideturtle()
raw_input();