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