-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion_turtle.py
More file actions
66 lines (54 loc) · 1.28 KB
/
recursion_turtle.py
File metadata and controls
66 lines (54 loc) · 1.28 KB
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
##############################################################################
# The program do not nothing special, only shows recursion with turtle
##############################################################################
import turtle
import time,random
turtle.tracer(20,0)
t = turtle.Turtle()
t.pencolor('maroon')
t.lt(90)
def tree(n):
if n == 0:
t.fd(30)
t.bk(30)
else:
t.fd(30)
t.lt(40)
tree(n - 1)
t.rt(80)
tree(n - 1)
t.lt(40)
t.bk(30)
def tree_2(n, d):
t.fd(d)
if n > 0:
t.lt(40)
tree_2(n - 1, d * .7)
t.rt(75)
tree_2(n - 1, d * .6)
t.lt(35)
t.bk(d)
def tree_3(n, d):
t.pensize(2 * n + 1)
t.fd(d)
if n == 0:
t.dot(10, 'green')
else:
uhol1 = random.randint(20, 40)
uhol2 = random.randint(20, 60)
t.lt(uhol1)
tree_3(n - 1, d * random.randint(40, 70) / 100)
t.rt(uhol1 + uhol2)
tree_3(n - 1, d * random.randint(40, 70) / 100)
t.lt(uhol2)
t.bk(d)
# tree(3)
# tree_2(5,80)
for i in range(30):
x = random.randint(-300, 300)
y = random.randint(-300, 100)
t.pu()
t.setpos(x,y)
t.pd()
tree_3(random.randint(3,7), random.randint(50,180))
time.sleep(2)