Fractal snowflake

I’m taking a Python class at the local Adult Ed. They just had us code a fractal snowflake to teach us recursion. It’s kinda fun, I suppose.

My code is below:

import turtle
 
def koch(t, length, n):
    if n == 0:
        return
    angle = 60
    t.fd(length*n)
    t.lt(angle)
    koch(t, length, n-1)
    t.rt(2*angle)
    koch(t, length, n-1)
    t.lt(angle)
    t.fd(length*n)

def snowflake(t,length,n):
    for i in range(6):
        koch(t, length,n)
        t.rt(60)
        
myrtel = turtle.Turtle()

snowflake(myrtel, 3, 5)
turtle.mainloop()

2 thoughts on “Fractal snowflake

  1. Russ Post author

    Yes, that must have gotten dropped when I copied it to the blog. I’ve added it so that others can copy the code.
    Thanks for catching it.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.