
    \h(4                        S SK Jr   S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJrJr  S SKr\" SS9 " S S5      5       r  " S S5      r!g! \ a	    \" S5      ef = f)    )RLockNz;pyglet is required for plotting.
 visit https://pyglet.org/)Integer)
SYMPY_INTS)GeometryEntity)PlotAxes)PlotMode)
PlotObject)
PlotWindow)parse_option_string)doctest_depends_on)is_sequence)sleepgetcwdlistdirpygletmodulesc                       \ rS rSrSr\" SS9S 5       rS rS rSS	 jr	S
 r
S rS rS rS rS rS rS rS rS rS rS rSrg)
PygletPlot   a  
Plot Examples
=============

See examples/advanced/pyglet_plotting.py for many more examples.

>>> from sympy.plotting.pygletplot import PygletPlot as Plot
>>> from sympy.abc import x, y, z

>>> Plot(x*y**3-y*x**3)
[0]: -x**3*y + x*y**3, 'mode=cartesian'

>>> p = Plot()
>>> p[1] = x*y
>>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)

>>> p = Plot()
>>> p[1] =  x**2+y**2
>>> p[2] = -x**2-y**2


Variable Intervals
==================

The basic format is [var, min, max, steps], but the
syntax is flexible and arguments left out are taken
from the defaults for the current coordinate mode:

>>> Plot(x**2) # implies [x,-5,5,100]
[0]: x**2, 'mode=cartesian'
>>> Plot(x**2, [], []) # [x,-1,1,40], [y,-1,1,40]
[0]: x**2, 'mode=cartesian'
>>> Plot(x**2-y**2, [100], [100]) # [x,-1,1,100], [y,-1,1,100]
[0]: x**2 - y**2, 'mode=cartesian'
>>> Plot(x**2, [x,-13,13,100])
[0]: x**2, 'mode=cartesian'
>>> Plot(x**2, [-13,13]) # [x,-13,13,100]
[0]: x**2, 'mode=cartesian'
>>> Plot(x**2, [x,-13,13]) # [x,-13,13,10]
[0]: x**2, 'mode=cartesian'
>>> Plot(1*x, [], [x], mode='cylindrical')
... # [unbound_theta,0,2*Pi,40], [x,-1,1,20]
[0]: x, 'mode=cartesian'


Coordinate Modes
================

Plot supports several curvilinear coordinate modes, and
they independent for each plotted function. You can specify
a coordinate mode explicitly with the 'mode' named argument,
but it can be automatically determined for Cartesian or
parametric plots, and therefore must only be specified for
polar, cylindrical, and spherical modes.

Specifically, Plot(function arguments) and Plot[n] =
(function arguments) will interpret your arguments as a
Cartesian plot if you provide one function and a parametric
plot if you provide two or three functions. Similarly, the
arguments will be interpreted as a curve if one variable is
used, and a surface if two are used.

Supported mode names by number of variables:

1: parametric, cartesian, polar
2: parametric, cartesian, cylindrical = polar, spherical

>>> Plot(1, mode='spherical')


Calculator-like Interface
=========================

>>> p = Plot(visible=False)
>>> f = x**2
>>> p[1] = f
>>> p[2] = f.diff(x)
>>> p[3] = f.diff(x).diff(x)
>>> p
[1]: x**2, 'mode=cartesian'
[2]: 2*x, 'mode=cartesian'
[3]: 2, 'mode=cartesian'
>>> p.show()
>>> p.clear()
>>> p
<blank plot>
>>> p[1] =  x**2+y**2
>>> p[1].style = 'solid'
>>> p[2] = -x**2-y**2
>>> p[2].style = 'wireframe'
>>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)
>>> p[1].style = 'both'
>>> p[2].style = 'both'
>>> p.close()


Plot Window Keyboard Controls
=============================

Screen Rotation:
    X,Y axis      Arrow Keys, A,S,D,W, Numpad 4,6,8,2
    Z axis        Q,E, Numpad 7,9

Model Rotation:
    Z axis        Z,C, Numpad 1,3

Zoom:             R,F, PgUp,PgDn, Numpad +,-

Reset Camera:     X, Numpad 5

Camera Presets:
    XY            F1
    XZ            F2
    YZ            F3
    Perspective   F4

Sensitivity Modifier: SHIFT

Axes Toggle:
    Visible       F5
    Colors        F6

Close Window:     ESCAPE

=============================

r   r   c                 |   SSK Jn  X l        SU l        [	        5       U l        0 U l        / U l        [        U 5      U l	        [        UR                  SS5      5      n[        S	0 UD6U l        U R                  R                  U R                  5        XS'   UR                  SS5      (       a  U R!                  5         gg)
aY  
Positional Arguments
====================

Any given positional arguments are used to
initialize a plot function at index 1. In
other words...

>>> from sympy.plotting.pygletplot import PygletPlot as Plot
>>> from sympy.abc import x
>>> p = Plot(x**2, visible=False)

...is equivalent to...

>>> p = Plot(visible=False)
>>> p[1] = x**2

Note that in earlier versions of the plotting
module, you were able to specify multiple
functions in the initializer. This functionality
has been dropped in favor of better automatic
plot plot_mode detection.


Named Arguments
===============

axes
    An option string of the form
    "key1=value1; key2 = value2" which
    can use the following options:

    style = ordinate
        none OR frame OR box OR ordinate

    stride = 0.25
        val OR (val_x, val_y, val_z)

    overlay = True (draw on top of plot)
        True OR False

    colored = False (False uses Black,
                     True uses colors
                     R,G,B = X,Y,Z)
        True OR False

    label_axes = False (display axis names
                        at endpoints)
        True OR False

visible = True (show immediately
    True OR False


The following named arguments are passed as
arguments to window initialization:

antialiasing = True
    True OR False

ortho = False
    True OR False

invert_mouse_zoom = False
    True OR False

   )
plot_modesNaxes r   visibleT )r   r   	_win_args_windowr   _render_lock
_functions	_pobjects
ScreenShot_screenshotr   popr   r   appendgetshow)selffargswin_argsr   axe_optionss        V/var/www/auris/envauris/lib/python3.13/site-packages/sympy/plotting/pygletplot/plot.py__init__PygletPlot.__init__   s    L 	!!!G%d+)(,,vr*BC+{+	dii(Q<<	4((IIK )    c                    U R                   (       a6  U R                   R                  (       d  U R                   R                  5         gSU R                  S'   U R                  R                  5         [        U 40 U R                  D6U l         g)zf
Creates and displays a plot window, or activates it
(gives it focus) if it has already been created.
Tr   N)r!   has_exitactivater    r   reset_resourcesr
   r+   s    r/   r*   PygletPlot.show   s\    
 << 5 5LL!!#(,DNN9%II%%'
 &d=dnn=DLr2   c                 \    U R                   (       a  U R                   R                  5         gg)z
Closes the plot window.
N)r!   closer7   s    r/   r:   PygletPlot.close  s      <<LL  r2   Nc                 <    U R                   R                  XU5        g)a  
Saves a screen capture of the plot window to an
image file.

If outfile is given, it can either be a path
or a file object. Otherwise a png image will
be saved to the current working directory.
If the format is omitted, it is determined from
the filename extension.
N)r&   saver+   outfileformatsizes       r/   	saveimagePygletPlot.saveimage  s     	gt4r2   c                     U R                   R                  5         0 U l        U R                  5         U R                   R	                  5         g)z(
Clears the function list of this plot.
Nr"   acquirer#   adjust_all_boundsreleaser7   s    r/   clearPygletPlot.clear  s;     	!!# !!#r2   c                      U R                   U   $ )z:
Returns the function at position i in the
function list.
)r#   r+   is     r/   __getitem__PygletPlot.__getitem__&  s    
 q!!r2   c                    [        U[        [        45      (       a  US:  d  [        S5      e[        U[        5      (       a  UnOQ[        U5      (       a  [        U[        5      (       a  U/n[        U5      S:X  a  gSU R                  0n[        U0 UD6nU(       aC  U R                  R                  5         X0R                  U'   U R                  R                  5         g[        SSR                  S U 5       5      -  5      e)z2
Parses and adds a PlotMode to the function
list.
r   z'Function index must be an integer >= 0.Nbounds_callbackzFailed to parse '%s'.z, c              3   8   #    U  H  n[        U5      v   M     g 7fNstr).0as     r/   	<genexpr>)PygletPlot.__setitem__.<locals>.<genexpr>F  s     51As   )
isinstancer   r   
ValueErrorr	   r   r   lenrG   r   r"   rF   r#   rH   join)r+   rM   argsfkwargss        r/   __setitem__PygletPlot.__setitem__-  s    
 1z7344a 3 4 4 dJ''A%%*T>*J*Jv4yA~')?)?@F$)&)A%%'!"OOA%%'4ii5556 7 7r2   c                     U R                   R                  5         U R                  U	 U R                  5         U R                   R	                  5         g)z:
Removes the function in the function list at
position i.
NrE   rL   s     r/   __delitem__PygletPlot.__delitem__H  s@    
 	!!#OOA !!#r2   c                     SnU R                   R                  5         XR                  ;   a  US-  nXR                  ;   a  M  U R                   R                  5         U$ )z6
Returns the first unused index in the function list.
r   r   )r"   rF   r#   rH   rL   s     r/   firstavailableindexPygletPlot.firstavailableindexR  sQ     !!#??"FA ??"!!#r2   c                 D    U R                  U R                  5       U5        g)zO
Parses and adds a PlotMode to the function
list at the first available index.
N)ra   rg   )r+   r^   s     r/   r(   PygletPlot.append]  s    
 	113T:r2   c                 ,    [        U R                  5      $ )z7
Returns the number of functions in the function list.
)r\   r#   r7   s    r/   __len__PygletPlot.__len__d  s     4??##r2   c                 6    U R                   R                  5       $ )z(
Allows iteration of the function list.
)r#   
itervaluesr7   s    r/   __iter__PygletPlot.__iter__j  s     ))++r2   c                     [        U 5      $ rS   rT   r7   s    r/   __repr__PygletPlot.__repr__p  s    4yr2   c                 R   Sn[        U R                  5      S:X  a  US-  nU$ U R                  R                  5         USR	                  U R                   Vs/ s H!  nSSU[        U R                  U   5      4-  PM#     sn5      -  nU R                  R                  5         U$ s  snf )z^
Returns a string containing a new-line separated
list of the functions in the function list.
r   r   z<blank plot>
z
%s[%i]: %s)r\   r#   r"   rF   r]   rU   rH   )r+   srM   s      r/   __str__PygletPlot.__str__s  s    
 t1$A 	 %%'%)__6%4 )B3tq7I3J+KK%46 7 7A%%'6s   (B$
c                 *   U R                   R                  5         U R                  R                  5         U R                   H5  nU R                  R                  U R                  U   R                  5        M7     U R                   R                  5         g rS   )r"   rF   r   reset_bounding_boxr#   adjust_boundsboundsrH   )r+   r_   s     r/   rG   PygletPlot.adjust_all_bounds  se    !!#		$$&AII##DOOA$6$=$=> !!!#r2   c                    [        S5        U R                  R                  5         U R                   Hv  nU R                  U   R                  nU R                  U   R
                  nU" 5       (       d  U" 5       (       d  MO  [        S5        U" 5       (       a  M  U" 5       (       a  M'  Mx     U R                  R                  5         g )Nr   )r   r"   rF   r#   _get_calculating_verts_get_calculating_cvertsrH   )r+   r_   rW   bs       r/   wait_for_calculations PygletPlot.wait_for_calculations  s    a!!#A"99A"::A##a ## !
 	!!#r2   )r#   r$   r"   r&   r    r!   r   Nr   )iX  i  )__name__
__module____qualname____firstlineno____doc__r   r0   r*   r:   rB   rI   rN   ra   rd   rg   r(   rl   rp   rs   rx   rG   r   __static_attributes__r   r2   r/   r   r      sp    ~@ ,V -Vt> !5$"76$	;$,$$r2   r   c                   6    \ rS rSrS rS rS rS	S jrS rSr	g)
r%   i  c                 V    Xl         SU l        S U l        SU l        SU l        SU l        g )NFr   r   )_plotscreenshot_requestedr?   r@   invisibleModeflag)r+   plots     r/   r0   ScreenShot.__init__  s,    
$)!"	r2   c                     U R                   $ rS   )r   r7   s    r/   __bool__ScreenShot.__bool__  s    (((r2   c           	         U R                   S:  a  U =R                   S-  sl         g U R                  R                  R                  5       u  pX-  S-  [        R
                  " [        R                  5      -  n[        R                  " U5      n[        R                  " SSX[        R                  [        R                  U5        SSKJn  UR                  SX4UR                  SSSS5      nUR!                  UR"                  5      R%                  U R&                  U R(                  5        SU l         SU l        U R,                  (       a%  U R                  R                  R/                  5         g g )	N   r      r   )ImageRGBArawF)r   r   r!   get_sizectypessizeofc_ubytecreate_string_bufferpglglReadPixelsGL_RGBAGL_UNSIGNED_BYTEPILr   
frombufferr   	transposeFLIP_TOP_BOTTOMr=   r?   r@   r   r   r:   )r+   size_xsize_yrA   imager   ims          r/   _execute_savingScreenShot._execute_saving  s
   99q=IINI++446}Qv}}V^^<<++D1Avs{{C<P<PRWXfv&6#ii1>
U**+00t{{K	$)!JJ$$& r2   Nc                    Xl         X l        X0l        SU l        U R                  R
                  (       a%  U R                  R
                  R                  (       a  SU R                  R                  S'   US   U R                  R                  S'   US   U R                  R                  S'   U R                  R                  R                  5         [        U R                  40 U R                  R                  D6U R                  l        SU l        U R                   c+  U R                  5       U l         [        U R                   5        g g )NTFr   r   widthr   height)r?   r@   rA   r   r   r!   r4   r    r   r6   r
   r   _create_unique_pathprintr>   s       r/   r=   ScreenShot.save  s    	$(!zz!!TZZ%7%7%@%@.3DJJ  +,0GDJJ  )-1!WDJJ  *JJOO++-!+DJJ!O$**:N:N!ODJJ!%D<<335DL$,,  r2   c                 l    [        5       n[        U5      nSnSn SU-  U;  a  USU-  -   n U$ US-  nM  )Nr   r   zplot_%s.pngz/plot_%s.pngr   r   )r+   cwdlpathrM   s        r/   r   ScreenShot._create_unique_path  sS    hCL 1$)^a// FA	 r2   )r   r   r@   r   r?   r   rA   r   )
r   r   r   r   r0   r   r   r=   r   r   r   r2   r/   r%   r%     s    )'& (
r2   r%   )"	threadingr   	pyglet.glglr   ImportErrorsympy.core.numbersr   sympy.external.gmpyr   sympy.geometry.entityr   #sympy.plotting.pygletplot.plot_axesr   #sympy.plotting.pygletplot.plot_moder   %sympy.plotting.pygletplot.plot_objectr	   %sympy.plotting.pygletplot.plot_windowr
   sympy.plotting.pygletplot.utilr   sympy.utilities.decoratorr   sympy.utilities.iterablesr   timer   osr   r   r   r   r%   r   r2   r/   <module>r      s    3
 ' * 0 8 8 < < > 8 1   K(v$ v$ )v$p= =[  3
 2 3 33s   A: :B	