Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/Tools/demo/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/Tools/demo/__pycache__/hanoi.cpython-36.pyc

3

� f�@sDdZddlmZmZdd�ZGdd�d�Zdd�Zed	kr@e�d
S)aV
Animated Towers of Hanoi using Tk with optional bitmap file in background.

Usage: hanoi.py [n [bitmapfile]]

n is the number of pieces to animate; default is 4, maximum 15.

The bitmap file can be any X11 bitmap file (look in /usr/include/X11/bitmaps for
samples); it is displayed as the background of the animation.  Default is no
bitmap.
�)�Tk�CanvascCsD|dkrdSt|d||||�||||�t|d||||�dS)Nr�)�hanoi)�n�a�b�c�report�r�5/opt/alt/python36/lib64/python3.6/Tools/demo/hanoi.pyrs
rc@s&eZdZddd�Zdd�Zdd�ZdS)	�TkhanoiNcCs:||_t�|_}t|�|_}|j�|j|d�|j|d�}}|rf|j|d|d|dd�|_d}|d}|d}	|	|d|dd}
}|
|||}}
g|_	|j
|
|||
d	d
�}|j	j|�|
|	||	}
}|j
|
|||
d	d
�}|j	j|�|
|	||	}
}|j
|
|||
d	d
�}|j	j|�|jj�|d}|	dd}d|}gggg|_
i|_|	|d|
|d}
}|
|||}}
||dtd|d�}x�t|dd�D]v}|j
|
|||
d
d
�}||j|<|j
dj|�|
|||}
}||d|
|d}}
|jj�|jjd��q�WdS)N�width�height�Zblue)�bitmapZ
foreground�
�rZblack)Zfill�rZred����)rr�tkr�canvasZpackZgetintZ
create_bitmapr�pegsZcreate_rectangle�append�update�pegstate�pieces�max�range�after)�selfrrrr	rrZpegwidthZ	pegheightZpegdist�x1�y1�x2�y2�p�pieceheightZ
maxpiecewidthZ
minpiecewidthZdx�irrr�__init__sP



zTkhanoi.__init__cCs�x|t|jddd|j�t|jddd|j�t|jddd|j�t|jddd|j�t|jddd|j�t|jddd|j�qWdS)Nrrr)rrr
)r!rrr�runOszTkhanoi.runcCsz|j|d|krt�|j|d=|j|}|j}|j|j|�\}}}}	x8|j|�\}
}}}
|
|krhP|j|dd�|jj�qLW|j|j|�\}}}}||d}x\|j|�\}
}}}
|
|d}||kr�P||kr�|j|dd�n|j|dd�|jj�q�W|
|}||t	|j|�d}x<|j|�\}
}}}
|
|k�rHP|j|dd�|jj��q*W|j|j
|�dS)Nrrrrrrr)r�RuntimeErrorrrZbboxrZmoverr�lenr)r!r(rrr&r	Zax1Zay1Zax2Zay2r"r#r$r%Zbx1Zby1Zbx2Zby2Z	newcenter�centerr'Z	newbottomrrrr
Ys@

zTkhanoi.report)N)�__name__�
__module__�__qualname__r)r*r
rrrrr
s
1
r
cCs�ddl}|jdd�r&t|jd�}nd}|jdd�rf|jd}|ddkr\|dd�}qjd|}nd}t||�}|j�dS)Nrr�r�@)�sys�argv�intr
r*)r3rr�hrrr�mains


r7�__main__N)�__doc__Ztkinterrrrr
r7r.rrrr�<module>
sd