-
Notifications
You must be signed in to change notification settings - Fork 0
/
snowflake.py
56 lines (44 loc) · 981 Bytes
/
snowflake.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
# Ashley Kang / Koch Snowflake Fractal
import turtle
def thue_morse(n):
# TODO
L = [0]
for i in range(1, n):
new_seq = L
for i in range(len(L)):
if L[i] == 0:
new_seq.append(1)
else:
new_seq.append(0)
print(new_seq)
L = new_seq
return L
#return L[:n]
'''
# Test function that generates Thue-Morse sequence
print(thue_morse(6))
'''
def koch(turt, width, n):
turt.penup()
turt.goto(0, 300)
turt.pendown()
# TODO
TM_seq = thue_morse(n)
#print(TMseq)
for i in TM_seq:
if TM_seq[i] == 0:
turt.forward(width)
else:
turt.left(60)
turtle.setup(800, 800)
wn = turtle.Screen()
turt = turtle.Turtle()
turt.speed(0)
#turtle.tracer(0.0)
# Test with first 10 elements in Thue-Morse sequence
koch(turt, 5, 10)
'''
# Bug? When n is a large number, the turtle freezes
koch(turt, 5, 10000)
'''
wn.exitonclick()