forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
koch curve.py
36 lines (32 loc) · 1.04 KB
/
koch curve.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
# importing the libraries
# turtle standard graphics library for python
import turtle
# function to create koch snowflake or koch curve
def snowflake(lengthSide, levels):
if levels == 0:
t.forward(lengthSide)
return
lengthSide /= 3.0
snowflake(lengthSide, levels - 1)
t.left(60)
snowflake(lengthSide, levels - 1)
t.right(120)
snowflake(lengthSide, levels - 1)
t.left(60)
snowflake(lengthSide, levels - 1)
# main function
if __name__ == "__main__":
t = turtle.Pen()
t.speed(0) # defining the speed of the turtle
length = 300.0 #
t.penup() # Pull the pen up – no drawing when moving.
# Move the turtle backward by distance, opposite to the direction the turtle is headed.
# Do not change the turtle’s heading.
t.backward(length / 2.0)
t.pendown()
for i in range(3):
# Pull the pen down – drawing when moving.
snowflake(length, 4)
t.right(120)
# To control the closing windows of the turtle
# mainloop()