File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments