Skip to content

Commit ecf33ab

Browse files
authored
Merge pull request prateekiiest#85 from Subhajit135/master
Koch Curve Implementation in Python
2 parents 5861ea5 + 3b5e035 commit ecf33ab

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Koch Curve/koch curve.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 #if the levels became zero then stop returning
10+
#to use the length side by 1/3rd of the previous
11+
#length since we are trisecting the line (koch curve logics to create the fractal)
12+
lengthSide /= 3.0
13+
snowflake(lengthSide, levels-1)
14+
left(60)
15+
snowflake(lengthSide, levels-1)
16+
right(120)
17+
snowflake(lengthSide, levels-1)
18+
left(60)
19+
snowflake(lengthSide, levels-1)
20+
21+
#main function
22+
if __name__ == "__main__":
23+
speed(0) #defining the speed of the turtle
24+
length = 300.0 #
25+
penup() #Pull the pen up – no drawing when moving.
26+
#Move the turtle backward by distance, opposite to the direction the turtle is headed.
27+
#Do not change the turtle’s heading.
28+
backward(length/2.0)
29+
pendown()
30+
for i in range(3):
31+
#Pull the pen down – drawing when moving.
32+
snowflake(length, 4)
33+
right(120)
34+
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)