-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkoch_snowflake.py
More file actions
36 lines (31 loc) · 787 Bytes
/
koch_snowflake.py
File metadata and controls
36 lines (31 loc) · 787 Bytes
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
## Koch Snowflake
import turtle
def koch_curve(length, depth):
if depth == 0:
turtle.forward(length)
else:
koch_curve(length/3, depth-1)
turtle.left(60)
koch_curve(length/3, depth-1)
turtle.right(120)
koch_curve(length/3, depth-1)
turtle.left(60)
koch_curve(length/3, depth-1)
def koche_snowflake(length, depth):
for i in range(3):
koch_curve(length, depth)
turtle.right(120)
def main():
turtle.setup(1200, 800)
turtle.penup()
turtle.goto(-350, 175)
turtle.pendown()
turtle.pensize(2)
turtle.speed(0)
length = 600
depth = 4 ## Change Depth
koche_snowflake(length, depth)
turtle.hideturtle()
turtle.done()
if __name__ == "__main__":
main()