.
This commit is contained in:
40
bac1/q1/04oct/ex6.py
Normal file
40
bac1/q1/04oct/ex6.py
Normal file
@ -0,0 +1,40 @@
|
||||
from uturtle import (
|
||||
umonsTurtle, wait,
|
||||
moveForward, moveBackward,
|
||||
turnLeft, turnRight,
|
||||
dropPen, usePen)
|
||||
|
||||
|
||||
def arbre(t, x, a, n):
|
||||
"""draw a tree
|
||||
|
||||
:t: turtle
|
||||
:x: taille du tronc de base
|
||||
:a: angle des branches
|
||||
:n: profondeur de l'arbre
|
||||
"""
|
||||
moveForward(t, x)
|
||||
arbre_rec(t, x, a, n)
|
||||
|
||||
|
||||
def arbre_rec(t, x, a, n):
|
||||
if n == 0:
|
||||
return
|
||||
turnLeft(t, a/2)
|
||||
moveForward(t, x)
|
||||
arbre_rec(t, x*5/6, a*5/6, n-1)
|
||||
moveBackward(t, x)
|
||||
|
||||
turnRight(t, a)
|
||||
moveForward(t, x)
|
||||
arbre_rec(t, x*5/6, a*5/6, n-1)
|
||||
moveBackward(t, x)
|
||||
|
||||
turnLeft(t, a/2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
turtle = umonsTurtle()
|
||||
turnLeft(turtle)
|
||||
arbre(turtle, 50, 45, 4)
|
||||
wait()
|
Reference in New Issue
Block a user