サンプルコード


コード1 (draw):

from __future__ import print_function, division
import math
import turtle

def draw(t, length, n):
    if n == 0:
        return
    angle = 50
    t.forward(length*n)
    t.left(angle)
    draw(t, length, n-1)
    t.right(2*angle)
    draw(t, length, n-1)
    t.left(angle)
    t.back(length*n)

gamera = turtle.Turtle()
gamera.reset()
gamera.speed(0)
length = 20
hierarchy = 5
# move to the starting point
gamera.penup()
gamera.back(length * hierarchy)
# draw
gamera.pendown()
draw(gamera, length, hierarchy)
# wait for the user to close the window
turtle.mainloop()



□演習3が終わったらクリック