# Use turtle graphics to make a koch snowflake fractal curve
import turtle # turtle graphics
turtle.speed(100) # sets speed of turtle to 100
#Code for 0th iteration
# turtle.forward(300)
#Code for 1st iteration
#turtle.forward(100)
#turtle.left(60)
#turtle.forward(100)
#turtle.right(120)
#turtle.forward(100)
#turtle.left(60)
#turtle.forward(100)
def snowflake(size,iter):
""""Draw a koch snowflake of given size (in pixels), and iter number of iterations.
Uses recursive strategy. """
if iter==0:
turtle.forward(size) #0th iter
else:
# below looks like above code 1st iteration, but with each forward command
# replaced with a snowflake of 1/3 the size, and one fewer iterations
snowflake(size/3.0,iter-1)
turtle.left(60)
snowflake(size/3.0,iter-1)
turtle.right(120)
snowflake(size/3.0,iter-1)
turtle.left(60)
snowflake(size/3.0,iter-1)
snowflake(300,3) # makes snowflake of size=300 pixels, and 3 iterations
turtle.mainloop() # stops turtle window from closing
#Command to pull pen up, to stop drawing track
#turtle.penup()
# Command to put pen down, will make track
#turtle.pendown()