Skip to content

Instantly share code, notes, and snippets.

@tobloef
Created August 25, 2017 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobloef/85bb570c1fb4dfc7246b84b0bfbd5b4b to your computer and use it in GitHub Desktop.
Save tobloef/85bb570c1fb4dfc7246b84b0bfbd5b4b to your computer and use it in GitHub Desktop.
Generates a Koch snowflake
from turtle import Turtle
def drawLine(turtle, size, depth, cur = 1):
if (cur < depth):
drawLine(turtle, size, depth, cur + 1)
turtle.left(60)
drawLine(turtle, size, depth, cur + 1)
turtle.right(120)
drawLine(turtle, size, depth, cur + 1)
turtle.left(60)
drawLine(turtle, size, depth, cur + 1)
else:
turtle.forward(size/(3**depth))
def drawSnowflake(size, depth):
t = Turtle()
t.speed(0)
for i in range(3):
drawLine(t, size, depth)
t.right(120)
drawSnowflake(1000, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment