Created
August 25, 2017 20:03
-
-
Save tobloef/85bb570c1fb4dfc7246b84b0bfbd5b4b to your computer and use it in GitHub Desktop.
Generates a Koch snowflake
This file contains hidden or 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
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