"""File: koch_curve0.py Purpose: Use TurtleWorld to draw a Koch curve Run: python koch_curve.py Input: The ``length'' of the curve. Output: A TurtleWorld window with a Koch curve. Note: This is a slightly modified version of the solution to the Koch curve exercise in Think Python: An Introduction to Software Design, Allen B. Downey """ from TurtleWorld import * def koch(t, n): """Draw a Koch curve having "length" n with turtle t""" if n < 3: fd(t, n) return m = n/3.0 koch(t, m) lt(t, 60) koch(t, m) rt(t, 120) koch(t, m) lt(t, 60) koch(t, m) def to_lower_left_corner(t): """Move t to the lower left corner of the window without drawing""" pu(t) rt(t) fd(t,200) rt(t) fd(t,200) rt(t) rt(t) pd(t) #---------------------------------------------------------------------- # Main program world = TurtleWorld() bob = Turtle() bob.delay = 0 to_lower_left_corner(bob) n = int(raw_input('How "long" should the curve be?\n ')) koch(bob, n) wait_for_user()