{|j d Z ddl G d de Z G d de Zd Zd Zd Ze d
k( r e Z
ee
e yy)a turtle-example-suite:
tdemo_minimal_hanoi.py
A minimal 'Towers of Hanoi' animation:
A tower of 6 discs is transferred from the
left to the right peg.
An imho quite elegant and concise
implementation using a tower class, which
is derived from the built-in type list.
Discs are turtles with shape "square", but
stretched to rectangles by shapesize()
---------------------------------------
To exit press STOP button
---------------------------------------
)*c e Zd Zd Zy)Discc t j | dd | j | j d|dz d | j |dz dd|dz z
| j y ) NsquareF)shapevisibleg ? g @r )Turtle__init__pu shapesize fillcolorst)selfns 1/usr/lib64/python3.12/turtledemo/minimal_hanoi.pyr
z
Disc.__init__ sV He< sAcE1%qtQ!B$' N)__name__
__module____qualname__r
r r r r s r r c " e Zd ZdZd Zd Zd Zy)Towerz-Hanoi tower, a subclass of built-in type listc || _ y)z-create an empty tower. x is x-position of pegN)x)r r s r r
zTower.__init__ s r c |j | j |j ddt | z z | j | y )Nij" )setxr setylenappendr ds r pushz
Tower.push# s5 tvv tBs4yL !Ar c R t j | }|j d |S )N )listpopr! r$ s r r* z Tower.pop' s HHTN sr N)r r r __doc__r
r&