HEX
Server: Apache
System: FreeBSD www860.sakura.ne.jp 13.0-RELEASE-p14 FreeBSD 13.0-RELEASE-p14 #2: Mon Dec 9 13:54:55 JST 2024 root@www5301.sakura.ne.jp:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64
User: yoyo0427 (1306)
PHP: 8.3.8
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.8/turtledemo/__pycache__/sorting_animate.cpython-38.pyc
U

q��a��@s�dZddlTddlZGdd�de�ZGdd�de�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zd%dd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"Zd#Zed$kr�e�Ze�dS)&a�

         sorting_animation.py

A minimal sorting algorithm animation:
Sorts a shelf of 10 blocks using insertion
sort, selection sort and quicksort.

Shelfs are implemented using builtin lists.

Blocks are turtles with shape "square", but
stretched to rectangles by shapesize()
 ---------------------------------------
       To exit press space button
 ---------------------------------------
�)�*Nc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�BlockcCsF||_tj|ddd�|��|�|ddd�|�d�|��dS)NZsquareF)�shapeZvisibleg�?��black)�size�Turtle�__init__Zpu�	shapesize�	fillcolor�st)�selfr�r�6/usr/local/lib/python3.8/turtledemo/sorting_animate.pyr	s
zBlock.__init__cCs|�d�dS)NZred�r�r
rrr�glow sz
Block.glowcCs|�d�dS)Nrrrrrr�unglow#szBlock.unglowcCsd�|j�S)NzBlock size: {0})�formatrrrrr�__repr__&szBlock.__repr__N)�__name__�
__module__�__qualname__r	rrrrrrrrsrc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ShelfcCs||_d|_dS)z.create a shelf. y is y-position of first blockij���N)�y�x)r
rrrrr	,szShelf.__init__cCsP|��\}}}|dd}|�|j|�|�|jdt|��|�|�dS)Nr��")r
�setyr�setxr�len�append)r
�d�width�_�y_offsetrrr�push1s
z
Shelf.pushcCs0||d�D]}|��\}}|�|d�qdS�Nr��posr�r
�i�bZxposr$rrr�_close_gap_from_i9szShelf._close_gap_from_icCs0||d�D]}|��\}}|�|d�qdSr'r(r*rrr�_open_gap_from_i>szShelf._open_gap_from_icCs,t�||�}|��|�d�|�|�|S)N��)�list�poprrr-)r
�keyr,rrrr1Cs


z	Shelf.popcCsb|�|�t�|||�|�|jd|�|��\}}}|dd}|�|j|�|��dS)Nrrr)	r.r0�insertrrr
rrr)r
r2r,r#r$r%rrrr3Js
zShelf.insertN)	rrrr	r&r-r.r1r3rrrrr*srcCs\t|�}td|�D]D}|}|dkrD||j||djkrD|d}q|�||�|��qdS)N�r�r �rangerr3r1)�shelf�lengthr+Zholerrr�isortTs 
r9cCsjt|�}td|d�D]N}|}t|d|�D]}||j||jkr,|}q,||kr|�||�|��qdS)Nrr4r5)r7r8�jZiminr+rrr�ssort]sr;cCsn||}|�||�|��|}t||�D].}||j|jkr(|�||�|��|d}q(|�||�|��|S�Nr4)r3r1r6r)r7�left�right�pivot_indexZpivotZstore_indexr+rrr�	partitiongs
r@cCs>||kr:|}t||||�}t|||d�t||d|�dSr<)r@�qsort)r7r=r>r?Zpivot_new_indexrrrrArs
rAcCs�t�t�ttd��}t�|�t|�D]@\}}t|tt��D](}t|j	|dkr@t�
|t�|��q@q*tt
�ttdd�t�dS)N�
r4��line)�disable_keys�clearr0r6�random�shuffle�	enumerater �srr3r1�	show_text�
instructions1�
instructions2�enable_keys)�targetr+�tr:rrr�	randomizeys
rQcCs(d|}tdd|�t|ddd�dS)Nrri����center)ZCourier�Zbold)ZalignZfont)Zgoto�write)�textrDrrrrK�srKcCs@t�t�td�tt�t�tt�ttdd�t�dS)NzSelection Sortr4rC)rErFrKr;rJrLrMrNrrrr�start_ssort�srVcCs@t�t�td�tt�t�tt�ttdd�t�dS)NzInsertion Sortr4rC)rErFrKr9rJrLrMrNrrrr�start_isort�srWcCsLt�t�td�ttdtt�d�t�tt�ttdd�t�dS)NZ	Quicksortrr4rC)	rErFrKrArJr rLrMrNrrrr�start_qsort�srXcCs(td�ad}|D]}t�t|��qdS)Ni8���)
�r��	r4�rB���)rrJr&r)Zvalsr+rrr�
init_shelf�sr`cCs,tdd�tdd�tdd�tdd�dS)NrJr+�q�r)�onkeyrrrrrE�s


rEcCs6ttd�ttd�ttd�ttd�ttd�dS)Nr+rJrarbZspace)rcrWrVrXrQZbyerrrrrN�s




rNcCs@t���t�t�t�tt�ttdd�t�t	�dS)Nr4rCZ	EVENTLOOP)
Z	getscreenZclearscreenZhtZpenupr`rKrLrMrN�listenrrrr�main�s
rezApress i for insertion sort, s for selection sort, q for quicksortz spacebar to quit, r to randomize�__main__)r)�__doc__ZturtlerGrrr0rr9r;r@rArQrKrVrWrXr`rErNrerLrMr�msgZmainlooprrrr�<module>s,*