
   gJG^_                       d Z ddl  G d de      Z G d de      Zd Zd Zd	 Ze	d
k(  r e       Z
 ee
        e        yy)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 Zd Zd Zy)Discc                     t         j                  | dd       | j                          | j                  d|dz  d       | j	                  |dz  dd|dz  z
         | j                          y )	NsquareF)shapevisibleg      ?   g      @r      )Turtle__init__pu	shapesize	fillcolorst)selfns     6/tmp/python/lib/python3.12/turtledemo/minimal_hanoi.pyr   zDisc.__init__   sV    He<	sAcE1%qtQ!B$'	    N)__name__
__module____qualname__r    r   r   r   r      s    r   r   c                   "    e Zd ZdZd Zd Zd Zy)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   zTower.__init__    s	    r   c                     |j                  | j                         |j                  ddt        |       z  z          | j	                  |       y )Nij"   )setxr   setylenappendr   ds     r   pushz
Tower.push#   s5    	tvv	tBs4yL !Ar   c                 R    t         j                  |       }|j                  d       |S )N   )listpopr!   r$   s     r   r*   z	Tower.pop'   s    HHTN	sr   N)r   r   r   __doc__r   r&   r*   r   r   r   r   r      s    3r   r   c                     | dkD  rBt        | dz
  |||       |j                  |j                                t        | dz
  |||       y y )Nr   r   )hanoir&   r*   )r   from_with_to_s       r   r-   r-   ,   sD    1uac5#u%ac5%% r   c                      t        d d       t                	 t        dt        t        t
               t        ddd       y # t        $ r Y y w xY w)Nspace   zpress STOP button to exitcenterCourier   boldalignfont)onkeyclearr-   t1t2t3write
Terminatorr   r   r   playrC   2   sG    	$w	GaR)#:	< s   (A 	AAc                  6   t                t                t        dd       t        d      at        d      at        d      at        ddd      D ]   } t        j                  t        |              " t        ddd	
       t        t        d       t                y)Nr   ii   r3   zpress spacebar to start gamer4   r5   r9   r2   	EVENTLOOP)htpenupgotor   r>   r?   r@   ranger&   r   rA   r<   rC   listen)is    r   mainrN   <   su    D%'44=	tB	qB	sB1Qr]
Q  

(68	$
Hr   __main__N)r+   turtler   r   r)   r   r-   rC   rN   r   msgprintmainloopr   r   r   <module>rT      sX   $ 6 D &  Z
&C	#JJ r   