o
    *ήc0                     @   s   d dl mZ d dlmZmZ d dlmZ ddlmZm	Z	m
Z
mZ d dlmZ G dd dZi ZG d	d
 d
Zed\ZZZZZZeeeeed< eeddddefed< eeddefg ded< eeddefg ded< dS )    )Basic)Symbolsymbols)lambdify   )interpolaterinterpolatecreate_boundsupdate_boundssiftc                   @   sH   e Zd Zg dg dfZdZdd Zdd Zdd	 Zd
d Zdd Z	dS )ColorGradient)皙?r   r   )?r   r   )              ?c                    s   t  dkrt | _ddg| _n2t  dkrCt  d dkr#td fddtdt  dD | _ fd	dtdt  dD | _t | jt | jksOJ d S )
N   r   r   r   zlen(args) should be evenc                       g | ]} | qS  r   .0iargsr   M/tmp/pip-target-vg8gfxp4/lib/python/sympy/plotting/pygletplot/color_scheme.py
<listcomp>       z*ColorGradient.__init__.<locals>.<listcomp>r   c                    r   r   r   r   r   r   r   r      r   )lenlistcolors	intervals
ValueErrorrange)selfr   r   r   r   __init__   s   
  zColorGradient.__init__c                 C   s,   t  }dd | jD |_| jd d  |_|S )Nc                 S   s   g | ]}|d d  qS Nr   )r   er   r   r   r          z&ColorGradient.copy.<locals>.<listcomp>)r   r   r    )r#   cr   r   r   copy   s   zColorGradient.copyc                 C   sN   t | j}d}||d k r%| j| |kr%|d7 }||d k r%| j| |ks|S )Nr   r   )r   r    )r#   vmr   r   r   r   _find_interval   s   
zColorGradient._find_intervalc                 C   sJ   |  |}t| j|d  | j| |}t| j|d  | | j| | |S )Nr   )r,   r   r    r   r   )r#   axisr*   r   r   r   r   _interpolate_axis$   s   
$zColorGradient._interpolate_axisc                 C   s"   | j }|d||d||d|fS )Nr   r   r   )r.   )r#   rgbr(   r   r   r   __call__)   s   zColorGradient.__call__N)
__name__
__module____qualname__r   r    r$   r)   r,   r.   r2   r   r   r   r   r      s    r   c                   @   sh   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dddZ
dddZdd Zdd ZdS )ColorSchemec                 O   s   || _ d t | _| _t|dkr$t|d ts$t|d r$|d | _n7t|dkrRt|d trR|d t	v rIt	|d  }|j|j
 | _| _ntd|d | _n	| |\| _| _|   t| jtsitdd S )Nr   r   	x,y,z,u,vzHColor gradient not properly initialized. (Not a ColorGradient instance.))r   r   fgradientr   
isinstancer   callablestrdefault_color_schemesr)   r   _interpret_args_test_color_functionr!   )r#   r   kwargscsr   r   r   r$   2   s   &zColorScheme.__init__c              
   C   s   d | j }}| |\}}| |}| |}ddd |D }dd |D }ddd |D }td||f }	t|dkrX|d }
z
t||
|
|
g}W n, tyW   |	w t|d	krw|\}}}z
t||||g}W n tyv   |	w td
t|dkrg }ndt|dkr|d }nYt|dkrz|\\}}}\}}}W n ty   tdw |}n8t|d	krz|\\}}\}}\}}W n t	y   tdw |||g|||gg}ntdddd |D  |rz	t
| }W ||fS  t	y } z
td|t|f d }~ww ||fS )N, c                 s       | ]}t |V  qd S r%   r<   )r   far   r   r   	<genexpr>L       z.ColorScheme._interpret_args.<locals>.<genexpr>c                 s   rC   r%   rD   r   sar   r   r   rF   M   rG   c                 s   s"    | ]}| d dk r|V  qdS )unboundr   N)findrH   r   r   r   rF   N   s     z4Could not interpret arguments %s as functions of %s.r   r      zDA ColorScheme must provide 1 or 3 functions in x, y, z, u, and/or v.r   z^If two color arguments are given, they must be given in the format (r1, g1, b1), (r2, g2, b2).zIf three color arguments are given, they must be given in the format (r1, r2), (g1, g2), (b1, b2). To create a multi-step gradient, use the syntax [0, colorStart, step1, color1, ..., 1, colorEnd].z3Don't know what to do with collection arguments %s.c                 s   rC   r%   rD   )r   lr   r   r   rF      rG   zFCould not initialize a gradient with arguments %s. Inner exception: %s)r9   
_sort_args_pop_symbol_list_fill_in_varsjoinr!   r   r   	TypeError	Exceptionr   r<   )r#   r   r8   r9   atomslistssf_strs_strf_errorfvfrfgfbgargsr1g1b1r2g2b2exr   r   r   r>   E   sr   





zColorScheme._interpret_argsc                 C   sz   g }|D ]"}d}|D ]}|d urt |tsd} nq
|r&|| || qt|dkr1|d S t|dkr9g S td)NTFr   r   z9Only one list of Symbols can be given for a color scheme.)r:   r   removeappendr   r!   )r#   rU   symbol_listsrM   markrV   r   r   r   rO      s"   

zColorScheme._pop_symbol_listc                 C   sZ  t d}td}t|dkr|S t|ttfs|t|dkr!|S |D ]}|d ur0t|ts0|q#dd tddD }t|dkrI|d |d< |S t|d	kri|d d ur[|d |d< |d d urg|d |d
< |S t|dkr|d d ur{|d |d< |d d ur|d |d< |d	 d ur|d	 |d	< t|d
kr|d |d< t|dkr|d
 |d
< |S )Nr7   zCould not find what to plot.r   c                 S   s   g | ]}t d | qS )z	unbound%i)r   r   r   r   r   r      r'   z-ColorScheme._fill_in_vars.<locals>.<listcomp>r      rL   r         )r   r!   r   r:   tupler   r   r"   )r#   r   defaultsv_errorrV   varsr   r   r   rP      sD   zColorScheme._fill_in_varsc                 C   s   t |dd dd\}}||fS )Nc                 S   s   t | ttfS r%   )r:   rm   r   )ar   r   r   <lambda>   s    z(ColorScheme._sort_args.<locals>.<lambda>T)binaryr   )r#   r   rU   rT   r   r   r   rN      s   
zColorScheme._sort_argsc                 C   s|   t | js	tdz| ddddd}t|dkrtdW d S  ty*   td ty4   td ty=   Y d S w )NzColor function is not callable.r   rL   zlength should be equal to 3zZColor function needs to accept x,y,z,u,v, as arguments even if it doesn't use all of them.z-Color function needs to return 3-tuple r,g,b.)r;   r8   r!   r   rR   AssertionErrorrS   )r#   resultr   r   r   r?      s   
z ColorScheme._test_color_functionc                 C   s*   z
|  |||||W S  ty   Y d S w r%   )r8   rS   )r#   xyzur*   r   r   r   r2      s
   zColorScheme.__call__Nc                 C   s(  t  }t }t|r|t|d  tt|D ]=}|| du r&|d n(|| \}}	}
|| d}}| ||	|
||}|durIt|}t|| || t|rU|  qtt|D ]5}|| durtdD ]}t|| d || d || | || |< qh| j||  ||< t|r|  q\|S )zt
        Apply this color scheme to a
        set of vertices over a single
        independent variable u.
        r   NrL   r   r   	r	   r   r;   r   r"   rg   r
   r   r9   )r#   vertsu_setset_leninc_posboundscverts_urv   rw   rx   ry   r*   r(   _cr   r   r   apply_to_curve   s8   


zColorScheme.apply_to_curvec                 C   s  t  }t }t|r|t|t| d  tt|D ]T}t }	tt|D ]C}
|| |
 du r7|	d n,|| |
 \}}}|| ||
 }}| |||||}|dur^t|}t|| |	| t|rj|  q'||	 qtt|D ]H}tt|D ]?}
|| |
 durtdD ]}t|| d || d || |
 | || |
 |< q| j|| |
  || |
< t|r|  qqw|S )zv
        Apply this color scheme to a
        set of vertices over two
        independent variables u and v.
        r   NrL   r   r   rz   )r#   r{   r|   v_setr}   r~   r   r   r   column_vrv   rw   rx   ry   r*   r(   r   r   r   r   apply_to_surface  sB   


zColorScheme.apply_to_surfacec                 C   s   d dd | jD S )NrB   c                 s   rC   r%   rD   )r   rq   r   r   r   rF   8  rG   z'ColorScheme.str_base.<locals>.<genexpr>)rQ   r   r#   r   r   r   str_base7  s   zColorScheme.str_basec                 C   s   d|    S )Nz%s)r   r   r   r   r   __repr__:  s   zColorScheme.__repr__)NN)r3   r4   r5   r$   r>   rO   rP   rN   r?   r2   r   r   r   r   r   r   r   r   r6   0   s    J+

&*r6   zx,y,z,t,u,vrainbow)r   r   
ףp=
?)r   r   r   Nzfade)
r   )皙?r   r   gffffff?)r   皙?r   g      ?)333333?r   r   ?)r   r   r   r   )r   r   r   zfade3)r   )r   r   r   r   )r   r   r   g?)ffffff?r   r   r   )r   r   r   g333333?)r   gffffff?r   r   )r   r   r   zfade4)sympy.core.basicr   sympy.core.symbolr   r   sympy.utilities.lambdifyr   utilr   r   r	   r
   sympy.utilities.iterablesr   r   r=   r6   rv   rw   rx   try   r*   r   r   r   r   <module>   s*    %  
