Skip to content

Commit e9bd54b

Browse files
authored
Koch Curve Implementation in Python
Tried to create snowflake fractals using koch curve in python using turtle programming.
1 parent 5861ea5 commit e9bd54b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Koch Curve/koch curve.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#importing the libraries
2+
#turtle standard graphics library for python
3+
from turtle import *
4+
5+
#function to create koch snowflake or koch curve
6+
def snowflake(lengthSide, levels):
7+
if levels == 0:
8+
forward(lengthSide)
9+
return
10+
lengthSide /= 3.0
11+
snowflake(lengthSide, levels-1)
12+
left(60)
13+
snowflake(lengthSide, levels-1)
14+
right(120)
15+
snowflake(lengthSide, levels-1)
16+
left(60)
17+
snowflake(lengthSide, levels-1)
18+
19+
#main function
20+
if __name__ == "__main__":
21+
speed(0) #defining the speed of the turtle
22+
length = 300.0 #
23+
penup() #Pull the pen up – no drawing when moving.
24+
#Move the turtle backward by distance, opposite to the direction the turtle is headed.
25+
#Do not change the turtle’s heading.
26+
backward(length/2.0)
27+
pendown()
28+
for i in range(3):
29+
#Pull the pen down – drawing when moving.
30+
snowflake(length, 4)
31+
right(120)
32+
mainloop() #To control the closing windows of the turtle

Koch Curve/output_2.mp4

620 KB
Binary file not shown.

0 commit comments

Comments
 (0)