forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursionVisualizer.py
72 lines (63 loc) · 1.52 KB
/
recursionVisualizer.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
import turtle
import random
t = turtle.Turtle()
num = random.randint(1, 1000)
t.right(num)
t.speed(num)
t.left(num)
def tree(i):
if i < 10:
return
else:
t.right(15)
t.forward(15)
t.left(20)
t.backward(20)
tree(2 * i / 5)
t.left(2)
tree(3 * i / 4)
t.left(2)
tree(i / 2)
t.backward(num / 5)
tree(random.randint(1, 100))
tree(random.randint(1, num))
tree(random.randint(1, num / 2))
tree(random.randint(1, num / 3))
tree(random.randint(1, num / 2))
tree(random.randint(1, num))
tree(random.randint(1, 100))
t.forward(num / 5)
t.right(2)
tree(3 * i / 4)
t.right(2)
tree(2 * i / 5)
t.right(2)
t.left(10)
t.backward(10)
t.right(15)
t.forward(15)
print("tree execution complete")
def cycle(i):
if i < 10:
return
else:
try:
tree(random.randint(1, i))
tree(random.randint(1, i * 2))
except:
print("An exception occured")
else:
print("No Exception occured")
print("cycle loop complete")
def fractal(i):
if i < 10:
return
else:
cycle(random.randint(1, i + 1))
cycle(random.randint(1, i))
cycle(random.randint(1, i - 1))
cycle(random.randint(1, i - 2))
print("fractal execution complete")
fractal(random.randint(1, 200))
print("Execution complete")
turtle.done()