o
    OZh                     @   s   d Z ddlZddlZzddlZddlmZ W n e	y!   e
dw dadddZdd Zdd	 Zd
d Zedkr>e  dS dS )ac   pg.examples.vgrade

This example demonstrates creating an image with numpy
python, and displaying that through SDL. You can look at the
method of importing numpy and pg.surfarray. This method
will fail 'gracefully' if it is not available.
I've tried mixing in a lot of comments where the code might
not be self explanatory, nonetheless it may still seem a bit
strange. Learning to use numpy for images like this takes a
bit of learning, but the payoff is extremely fast image
manipulation in python.

For Pygame 1.9.2 and up, this example also showcases a new feature
of surfarray.blit_surface: array broadcasting. If a source array
has either a width or height of 1, the array is repeatedly blitted
to the surface along that dimension to fill the surface. In fact,
a (1, 1) or (1, 1, 3) array results in a simple surface color fill.

Just so you know how this breaks down. For each sampling of
time, 30% goes to each creating the gradient and blitting the
array. The final 40% goes to flipping/updating the display surface

The window will have no border decorations.

The code also demonstrates use of the timer events.
    Nz;This example requires numpy and the pygame surfarray modulec                 C   sT   | s	t j adS t j }|t d d }t|  d| dd| dd |adS )	z"simple routine to time python codeNg     @@gMbP? z	 seconds	g      ?z.2fZfps)pgtimeZ	get_tickstimerprint)messagenowZruntime r	   E/var/www/auris/lib/python3.10/site-packages/pygame/examples/vgrade.py	stopwatch*   s   

 r   c                 C   s   t j|dd}t j|dd}|| }|  \}}t j|dd| }t |ddt jf dgd}||| d }|d	t jddddf }tj	| |S )
z(creates a new 3d vertical gradient arrayF)copyfloat)ZdtypeN      intZuint8)
nparrayget_sizeZarangerepeatZnewaxisZastyper   	surfarrayZ	map_array)surfZtopcolorZbottomcolordiffwidthheightcolumnr	   r	   r
   VertGradientColumn6   s   r   c                 C   sL   t   tddd}t| |d |d }tj| | tj  t d dS )z"choose random colors and show themr      )   r   r   z	Gradient:N)	r   	np_randomrandintr   r   r   Z
blit_arraydisplayflip)r   colorsr   r	   r	   r
   DisplayGradientG   s   
r#   c                  C   s   t   t j  d} dtjd< t j| t jd}t j	
t j t jt jd 	 t j	 }|jt jt jt jfv r:n|jt jkrDt| q)t   d S )N)iX  i  1ZSDL_VIDEO_CENTEREDr   i  )r   initZmixerquitosenvironr    set_modeZNOFRAMEeventZset_blockedZMOUSEMOTIONr   Z	set_timerZ	USEREVENTwaittypeZQUITZKEYDOWNZMOUSEBUTTONDOWNr#   )sizescreenr*   r	   r	   r
   mainQ   s   


r/   __main__)N)__doc__r'   Zpygamer   numpyr   Znumpy.randomrandomr   ImportError
SystemExitr   r   r   r#   r/   __name__r	   r	   r	   r
   <module>   s"   


