サンプルコード


コード2 (koch, snowflake):

from __future__ import print_function, division
import math
import turtle

def koch(t, length, n):
    if n == 0:
        t.forward(length)
        return
    angle = 60
    koch(t, length/3, n-1)
    t.left(angle)
    koch(t, length/3, n-1)
    t.right(2*angle)
    koch(t, length/3, n-1)
    t.left(angle)
    koch(t, length/3, n-1)

def snowflake(t, length, n):
    for i in range(3):
        koch(t, length, n)
        t.right(120)

gamera = turtle.Turtle()
gamera.reset()
gamera.speed(0)
length = 500
hierarchy = 3
# move to the starting point
gamera.penup()
gamera.goto(-length/2, length/2)
# draw 
gamera.pendown()
snowflake(gamera, length, hierarchy)
# wait for the user to close the window
turtle.mainloop()