forked from xavier/KidsCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcercles.py
More file actions
45 lines (37 loc) · 884 Bytes
/
cercles.py
File metadata and controls
45 lines (37 loc) · 884 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
import turtle
t = turtle.Pen()
def cercle(t, rayon):
""" Dessine un cercle ayant pour centre la position actuelle de la tortue """
t.penup()
t.right(90)
t.forward(rayon)
t.left(90)
t.pendown()
t.circle(rayon, 360)
t.penup()
t.left(90)
t.forward(rayon)
t.right(90)
t.pendown()
def couleur(ordre):
teinte = (1.0/(ordre+1.25))
return (teinte, teinte, teinte)
def cercles(t, rayon, nombre_cercles, ordre):
t.color(couleur(ordre))
cercle(t, rayon)
if ordre > 0:
distance = rayon * 2
nouveau_rayon = rayon / 3
angle = 360/nombre_cercles
for i in range(nombre_cercles):
t.left(angle)
t.penup()
t.forward(distance)
t.pendown()
cercles(t, nouveau_rayon, nombre_cercles, ordre-1)
t.penup()
t.backward(distance)
t.pendown()
t.speed("fastest")
cercles(t, 100, 6, 3)
raw_input()