Start New Discussion within our Software Development Community

Using Python module turtle to draw a Koch snow fractal.

''' turtle_KochSnowFlake_full.py
use Python's module turtle to draw a Koch snowflake
tested with Python27 and Python33  by  vegseat  16oct2013
'''

import turtle as tu

def snowflake(side, levels):
    if levels == 0:
        tu.forward(side)
        return
    side /= 3.0
    snowflake(side, levels-1)
    tu.left(60)
    snowflake(side, levels-1)
    tu.right(120)
    snowflake(side, levels-1)
    tu.left(60)
    snowflake(side, levels-1)

def full_snowflake(side, levels):
    for k in range(3):
        snowflake(side, levels)
        tu.right(120)


if __name__ == "__main__":
    tu.title("Drawing a Koch snowflake")
    tu.bgcolor('blue')
    # values for speed are 'fastest' (no delay), 'fast', (delay 5ms),
    # 'normal' (delay 10ms), 'slow' (delay 15ms), and 'slowest' (delay 20ms)
    tu.speed('fastest')
    length = 300.0
    tu.penup()
    # start drawing here to center the drawing
    tu.goto(-length//2, length//2)
    tu.pendown()
    tu.color('white')
    tu.begin_fill()    
    full_snowflake(length, 4)
    tu.end_fill()
    tu.mainloop()
The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.