41 lines
		
	
	
		
			729 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			729 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| 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()
 |