Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/Tools/demo/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/Tools/demo/__pycache__/hanoi.cpython-37.opt-1.pyc

B

� 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/python37/lib64/python3.7/Tools/demo/hanoi.pyrs
rc@s&eZdZddd�Zdd�Zdd�ZdS)	�TkhanoiNcCs:||_t�|_}t|�|_}|��|�|d�|�|d�}}|rf|j|d|d|dd�|_d}|d}|d}	|	|d|dd}
}|
|||}}
g|_	|j
|
|||
d	d
�}|j	�|�|
|	||	}
}|j
|
|||
d	d
�}|j	�|�|
|	||	}
}|j
|
|||
d	d
�}|j	�|�|j��|d}|	dd}d|}gggg|_
i|_|	|d|
|d}
}|
|||}}
||dtd|d�}x�t|dd
�D]v}|j
|
|||
dd
�}||j|<|j
d�|�|
|||}
}||d|
|d}}
|j��|j�d��q�WdS)N�width�height�Zblue)�bitmapZ
foreground�
�rZblack)Zfill�r���Zred�)rr�tkr�canvasZpackZgetintZ
create_bitmapr�pegsZcreate_rectangle�append�update�pegstate�pieces�max�rangeZafter)�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|�\}}}}	x8|�|�\}
}}}
|
|krhP|�|dd�|j��qLW|�|j|�\}}}}||d}x\|�|�\}
}}}
|
|d}||kr�P||kr�|�|dd�n|�|dd�|j��q�W|
|}||t	|j|�d}x<|�|�\}
}}}
|
|k�rHP|�|dd�|j���q*W|j|�
|�dS)Nrrrr)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||�}|��dS)Nrr�r�@)�sys�argv�intr
r))r2rr�hrrr�mains


r6�__main__N)�__doc__Ztkinterrrrr
r6r-rrrr�<module>
sd