-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragon.py
60 lines (46 loc) · 1.09 KB
/
dragon.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
# Ashley Kang / Dragon Curve Fractal
import turtle
def unfold_dragon(n):
seq = [0]
#print(seq)
# TODO
for i in range(1, n):
new_seq = seq
L_reversed = seq[::-1]
C = []
for i in range(len(L_reversed)):
if L_reversed[i] == 0:
C.append(1)
else:
C.append(0)
new_seq.append(0)
for i in range(len(C)):
new_seq.append(C[i])
#print(new_seq)
seq = new_seq
return new_seq
'''
# Test function that generates "unfolding the dragon" sequence
print(unfold_dragon(4))
'''
def dragon(turt, width, n):
# TODO
dragon_list = unfold_dragon(n)
for i in dragon_list:
if i == 0:
turt.right(90)
else:
turt.left(90)
turt.forward(10)
turtle.setup(800, 800)
wn = turtle.Screen()
turt = turtle.Turtle()
turt.speed(0)
#turtle.tracer(0.0)
# Test with first 10 elements in "unfolding the dragon" sequence
dragon(turt, 5, 10)
'''
# Bug? When n is a large number, the turtle freezes
dragon(turt, 5, 10000)
'''
wn.exitonclick()