Created
November 8, 2016 03:25
-
-
Save IanMcT/df6a58e5cc962c9de201a3df5b39e3a7 to your computer and use it in GitHub Desktop.
Koch fractals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
def koch(t, order, size): | |
""" | |
Make turtle t draw a Koch fractal of 'order' and 'size'. | |
Leave the turtle facing the same direction. | |
""" | |
if order == 0: # The base case is just a straight line | |
t.forward(size) | |
else: | |
koch(t, order-1, size/3) # Go 1/3 of the way | |
t.left(60) | |
koch(t, order-1, size/3) | |
t.right(120) | |
koch(t, order-1, size/3) | |
t.left(60) | |
koch(t, order-1, size/3) | |
wn = turtle.Screen() # creates a graphics window | |
alex = turtle.Turtle() # create a turtle named alex | |
koch(alex,4,300) | |
wn.exitonclick() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment