-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursive_tree.py
80 lines (66 loc) · 1.62 KB
/
recursive_tree.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import turtle
turtle.speed(10);
turtle.tracer(0, 0)
# turtle.Screen().mainloop()
#
twig_size = 35
# flakes = 3
# twig_amount = 3
#
# def createArm(amount, iteration, twig_amount):
# if (iteration < 1):
# return
# turtle.left(360 / amount)
# turtle.fd(twig_size)
# createTwig(twig_amount)
# turtle.bk(twig_size * (twig_amount + 1))
# createArm(amount, iteration - 1, twig_amount)
#
def createTwig(amount, size):
if (amount < 1):
return
turtle.fd(size)
turtle.bk(size)
turtle.left(45)
turtle.fd(size)
turtle.bk(size)
turtle.right(90)
turtle.fd(size)
turtle.bk(size)
turtle.left(45)
# turtle.fd(twig_size)
# createTwig(amount - 1, size)
def createLeftRightBranches(size, branches):
for i in range(1, branches):
turtle.fd(size)
turtle.left(20)
createTwig(1, size)
size = size / 1.25
for i in range(1, branches):
size = size * 1.25
createTwig(1, size)
turtle.right(20)
turtle.bk(size)
for i in range(1, branches):
turtle.fd(size)
turtle.right(20)
createTwig(1, size)
size = size / 1.25
for i in range(1, branches):
size = size * 1.25
createTwig(1, size)
turtle.left(20)
turtle.bk(size)
def createBranch(size):
for i in range(1, 5):
turtle.fd(size * 3)
createLeftRightBranches(size, 6)
turtle.bk(size * 3 * 4)
turtle.pendown()
# createArm(flakes, flakes, twig_amount)
# createBranch(20)
for i in range(1,5):
turtle.left(30)
createBranch(20)
turtle.update()
turtle.Screen().exitonclick()