2 """ turtle-example-suite:
6 A minimal 'Towers of Hanoi' animation:
7 A tower of 6 discs is transferred from the
10 An imho quite elegant and concise
11 implementation using a tower class, which
12 is derived from the built-in type list.
14 Discs are turtles with shape "square", but
15 stretched to rectangles by shapesize()
16 ---------------------------------------
17 To exit press STOP button
18 ---------------------------------------
23 def __init__(self
, n
):
24 Turtle
.__init
__(self
, shape
="square", visible
=False)
26 self
.shapesize(1.5, n
*1.5, 2) # square-->rectangle
27 self
.fillcolor(n
/6., 0, 1-n
/6.)
31 "Hanoi tower, a subclass of built-in type list"
32 def __init__(self
, x
):
33 "create an empty tower. x is x-position of peg"
37 d
.sety(-150+34*len(self
))
44 def hanoi(n
, from_
, with_
, to_
):
46 hanoi(n
-1, from_
, to_
, with_
)
48 hanoi(n
-1, with_
, from_
, to_
)
54 write("press STOP button to exit",
55 align
="center", font
=("Courier", 16, "bold"))
59 ht(); penup(); goto(0, -225) # writer turtle
63 # make tower of 6 discs
64 for i
in range(6,0,-1):
66 # prepare spartanic user interface ;-)
67 write("press spacebar to start game",
68 align
="center", font
=("Courier", 16, "bold"))
73 if __name__
=="__main__":