This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_fractal.py
71 lines (53 loc) · 1.61 KB
/
random_fractal.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
import turtle
def fractal(number_of_iterations):
string = "0"
while number_of_iterations > 0:
string = iterate(string)
number_of_iterations -= 1
draw(string)
def iterate(string):
new_string = ""
for n in string:
if n == "0":
new_string += "1"
else:
new_string += "0"
#regular dragon curve
return string + "0" + new_string[::-1]
#wiggly dragon curve
#return (string + "0" + new_string[::-1])[1::]
#maze dragon curve
#return (string + "010" + new_string[::-1])[0:-1:]
#maze triangle
#return (string + "010" + new_string[::-1])[::-1][0:-1:]
#weird square dragon curve
#return string + "010" + new_string[::-1]
#spiky dragon curve
#return string + "1" + new_string[::-1]
#crazy triangle
#return string[::-1] + "010" + new_string
def draw(string):
"""uses turtle to draw the curve"""
t = turtle.Turtle()
t.speed(0)
t.shape("blank")
for n in string:
if n == "0":
t.right(90)
elif n == "1":
t.left(90)
t.forward(4)
"""
#wiggly dragon curve
return (string + "0" + new_string[::-1])[1::]
#maze dragon curve
(string + "010" + new_string[::-1])[0:-1:]
#maze triangle
return (string + "010" + new_string[::-1])[::-1][0:-1:]
#weird square dragon curve
return string + "010" + new_string[::-1]
#spiky dragon curve
return string + "1" + new_string[::-1]
#crazy triangle
return string[::-1] + "010" + new_string
"""