import turtle
import math
wn = turtle.Screen()
wx = wn.window_width()*.5
wh = wn.window_height()*.5
base_triangle_length = 2.0/math.sqrt(3.0)*wh
depth = 2
turtle.speed(50*(depth+1))
turtle.penup()
turtle.setposition((-wx/2,-wh/2))
turtle.pendown()
turtle.left(60)
def draw_koch_segment(t, run, mydepth, depth):
if mydepth == depth:
t.fd(run)
else:
myrun = run/3.0
draw_koch_segment(t, myrun, mydepth+1, depth)
t.left(60)
draw_koch_segment(t, myrun, mydepth+1, depth)
t.right(120)
draw_koch_segment(t, myrun, mydepth+1, depth)
t.left(60)
draw_koch_segment(t, myrun, mydepth+1, depth)
for ii in range(3):
draw_koch_segment(turtle, base_triangle_length, 0, depth)
turtle.right(120)
Post Views: 739
Leave a Reply
You must be logged in to post a comment.