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()

The post Fractal snowflake appeared first on OnWords.

 •  0 comments  •  flag
Share on Twitter
Published on February 11, 2019 15:35
No comments have been added yet.