B
    ʽep                 @   s  d Z ddlmZmZ ddlZddlZddlZdZdgddgdgd	gd
gdgdgdgdgdgdgdgdgddgdgdgdgdgdgddgdgdgdgdgd gd!gd"gd#gd$gd%gd&gd'gd(d)gd*gd+gd,d-gd.d/gd0gd1gd2gd3gd4gd5gd6gd7d8gd9gd:gd;gd<gd=gd>gd?gd@gdAgdBgdCgdDgdEgdFgdGgdHgdIdJgdKgdLgdMgdNgdOgdPgdQgdRgdSgdTgdUgdVgdWgdXgdYgdZgd[gd\d]gd^gd_gd`gdagdbgdcgddgdegdfgdggdhgdigdjgdkgdlgdmgdngdogdpgdqgdrgdsgdtgdugdvgdwgdxgdygdzgd{gd|gd}d~gdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdZe	dd e
 D ZedZedZG dd dZe ZG dd dZG dd dZe Ze Zdd Zdd Zdd ZdddZdd Zdd ZdddZdd Zdd Zdd Zdd Zdd Z dd Z!dd Z"dd Z#dd Z$G ddÄ de%Z&dd Z'dd Z(ddǄ Z)dS )a  Color Library

.. :doctest:

This module defines several color formats that can be converted to one or
another.

Formats
-------

HSL:
    3-uple of Hue, Saturation, Lightness all between 0.0 and 1.0

RGB:
    3-uple of Red, Green, Blue all between 0.0 and 1.0

HEX:
    string object beginning with '#' and with red, green, blue value.
    This format accept color in 3 or 6 value ex: '#fff' or '#ffffff'

WEB:
    string object that defaults to HEX representation or human if possible

Usage
-----

Several function exists to convert from one format to another. But all
function are not written. So the best way is to use the object Color.

Please see the documentation of this object for more information.

.. note:: Some constants are defined for convenience in HSL, RGB, HEX

    )with_statementprint_functionNgƠ>ZBlackZNavyZNavyBlueZDarkBlueZ
MediumBlueBlueZ	DarkGreenGreenZDarkCyanZDeepSkyBlueZDarkTurquoiseZMediumSpringGreenZLimeZSpringGreenZCyanZAquaZMidnightBlueZ
DodgerBlueZLightSeaGreenZForestGreenZSeaGreenZDarkSlateGrayZDarkSlateGreyZ	LimeGreenZMediumSeaGreenZ	TurquoiseZ	RoyalBlueZ	SteelBlueZDarkSlateBlueZMediumTurquoiseZIndigoZDarkOliveGreenZ	CadetBlueZCornflowerBlueZMediumAquamarineZDimGrayZDimGreyZ	SlateBlueZ	OliveDrabZ	SlateGrayZ	SlateGreyZLightSlateGrayZLightSlateGreyZMediumSlateBlueZ	LawnGreenZ
ChartreuseZ
AquamarineZMaroonZPurpleZOliveZGrayZGreyZLightSlateBlueZSkyBlueZLightSkyBlueZ
BlueVioletZDarkRedZDarkMagentaZSaddleBrownZDarkSeaGreenZ
LightGreenZMediumPurpleZ
DarkVioletZ	PaleGreenZ
DarkOrchidZYellowGreenZSiennaZBrownZDarkGrayZDarkGreyZ	LightBlueZGreenYellowZPaleTurquoiseZLightSteelBlueZ
PowderBlueZ	FirebrickZDarkGoldenrodZMediumOrchidZ	RosyBrownZ	DarkKhakiSilverZMediumVioletRedZ	IndianRedZPeruZ	VioletRedZ	ChocolateZTanZ	LightGrayZ	LightGreyZThistleZOrchidZ	GoldenrodZPaleVioletRedZCrimsonZ	GainsboroZPlumZ	BurlywoodZ	LightCyanZLavenderZ
DarkSalmonZVioletZLightGoldenrodZPaleGoldenrodZ
LightCoralZKhakiZ	AliceBlueZHoneydewZAzureZ
SandyBrownZWheatZBeigeZ
WhiteSmokeZ	MintCreamZ
GhostWhiteZSalmonZAntiqueWhiteZLinenZLightGoldenrodYellowZOldLaceRedZMagentaZFuchsiaZDeepPinkZ	OrangeRedZTomatoZHotPinkZCoralZ
DarkOrangeZLightSalmonZOrangeZ	LightPinkZPinkZGoldZ	PeachPuffZNavajoWhiteZMoccasinZBisqueZ	MistyRoseZBlanchedAlmondZ
PapayaWhipZLavenderBlushZSeashellZCornsilkZLemonChiffonZFloralWhiteZSnowZYellowZLightYellowZIvoryWhite))r   r   r   )r   r      )r   r      )r   r      )r   r      )r   d   r   )r   r	   r   )r   r
   r
   )r      r   )r         )r         )r   r   r   )r   r      )r   r   r   )   r   p   )      r   )          )"   r
   r   ).   r
   W   )/   O   r   )2   r   r    )<      q   )@         )A   i      )F         )H   =   r
   )r-   r      )K   r   r+   )U   k   r   )_         )r         )f   r   r   )r(   r(   r(   )j   Z   r   )r2      #   )r   r	   r   )w         ){   h      )|      r   )r   r   r   )r   r      )r	   r   r   )r	   r   r	   )r	   r	   r   )r	   r	   r	   )   r   r   )   r      )rG   r   r   )   +      )r
   r   r   )r
   r   r
   )r
   E      )      rN   )r   rB   r   )   r      )   r      )      rT   )r?   r    r/   )r   r   r    )r5   R   -   )   *   rY   )   rZ   rZ   )         )r[   r   r   )   rB   rB   )         )r_   r%   r]   )r   r   r   )         )   r1   rS   )rO   rN   rN   )      r2   )   rh   rh   )         )r   \   rl   )r   rk   ?   )r&   r   r   )   r(   r   )rn   r,      )rS   rS   rS   )r\   r   r\   )   r      )rp   rX   r   )rQ   r   rP   )      r!   )rr   rr   rr   )   r5   rt   )ra   rb   rG   )r%   r   r   )r]   r]   r   )      z   )rB   r+   rB   )rB   rt   r+   )rB      r   )   r	   r	   )ry   r]   ro   )ry      r   )ry   r   ry   )ry   r   r   )      `   )   ra   r"   )r~   r~   rr   )r~   r~   r~   )r~   r   r   )rz   rz   r   )r   r	   r   )r   rH      )r   ry   r]   )r   r   rn   )   r~   r]   )r   r   r   )r   r   r   )r   rs   rP   )r   rL   r   )r   c   G   )r   r(   r,   )r   r   P   )r   ro   r   )r   r5   rw   )r   rX   r   )r         )r   rh      )r   r   r   )r   rp      )r   ra   r[   )r         )r   r   r`   )r   r   r)   )r   rH   r   )r         )r   ry   r~   )r   r~   rB   )r   rz   rr   )r   r   r   )r   r   ry   )r   r   r   )r   r   r   )r   r   r%   )r   r   ry   )r   r   r   c             c   s(   | ] \}}|D ]}|  |fV  qqd S )N)lower).0rgbnamesname r   I/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/colour.py	<genexpr>   s   r   z^#[0-9a-fA-F]{6}$z^#[0-9a-fA-F]{3}$c               @   s   e Zd Zdd ZdS )C_HSLc             C   s@   |  }|tkr*ttdd t| D S td| j|f d S )Nc             s   s   | ]}|d  V  qdS )g     o@Nr   )r   vr   r   r   r      s    z$C_HSL.__getattr__.<locals>.<genexpr>z%s instance has no attribute %r)r   COLOR_NAME_TO_RGBrgb2hsltupleAttributeError	__class__)selfvaluelabelr   r   r   __getattr__   s
    zC_HSL.__getattr__N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdd ZdS )C_RGBa?  RGB colors container

    Provides a quick color access.

    >>> from colour import RGB

    >>> RGB.WHITE
    (1.0, 1.0, 1.0)
    >>> RGB.BLUE
    (0.0, 0.0, 1.0)

    >>> RGB.DONOTEXISTS  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    AttributeError: ... has no attribute 'DONOTEXISTS'

    c             C   s   t tt|S )N)hsl2rgbgetattrHSL)r   r   r   r   r   r      s    zC_RGB.__getattr__N)r   r   r   __doc__r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdd ZdS )C_HEXa-  RGB colors container

    Provides a quick color access.

    >>> from colour import HEX

    >>> HEX.WHITE
    '#fff'
    >>> HEX.BLUE
    '#00f'

    >>> HEX.DONOTEXISTS  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    AttributeError: ... has no attribute 'DONOTEXISTS'

    c             C   s   t tt|S )N)rgb2hexr   RGB)r   r   r   r   r   r     s    zC_HEX.__getattr__N)r   r   r   r   r   r   r   r   r   r      s   r   c       	      C   s   dd | D \}}}dt  |  kr0dt  ks:n tddt  |  krVdt  ks`n td|dkrr|||fS |dk r|d|  }n|| ||  }d	| | }t|||d
 }t|||}t|||d
 }|||fS )aB  Convert HSL representation towards RGB

    :param h: Hue, position around the chromatic circle (h=1 equiv h=0)
    :param s: Saturation, color saturation (0=full gray, 1=full color)
    :param l: Ligthness, Overhaul lightness (0=full black, 1=full white)
    :rtype: 3-uple for RGB values in float between 0 and 1

    Hue, Saturation, Range from Lightness is a float between 0 and 1

    Note that Hue can be set to any value but as it is a rotation
    around the chromatic circle, any value above 1 or below 0 can
    be expressed by a value between 0 and 1 (Note that h=0 is equiv
    to h=1).

    This algorithm came from:
    http://www.easyrgb.com/index.php?X=MATH&H=19#text19

    Here are some quick notion of HSL to RGB conversion:

    >>> from colour import hsl2rgb

    With a lightness put at 0, RGB is always rgbblack

    >>> hsl2rgb((0.0, 0.0, 0.0))
    (0.0, 0.0, 0.0)
    >>> hsl2rgb((0.5, 0.0, 0.0))
    (0.0, 0.0, 0.0)
    >>> hsl2rgb((0.5, 0.5, 0.0))
    (0.0, 0.0, 0.0)

    Same for lightness put at 1, RGB is always rgbwhite

    >>> hsl2rgb((0.0, 0.0, 1.0))
    (1.0, 1.0, 1.0)
    >>> hsl2rgb((0.5, 0.0, 1.0))
    (1.0, 1.0, 1.0)
    >>> hsl2rgb((0.5, 0.5, 1.0))
    (1.0, 1.0, 1.0)

    With saturation put at 0, the RGB should be equal to Lightness:

    >>> hsl2rgb((0.0, 0.0, 0.25))
    (0.25, 0.25, 0.25)
    >>> hsl2rgb((0.5, 0.0, 0.5))
    (0.5, 0.5, 0.5)
    >>> hsl2rgb((0.5, 0.0, 0.75))
    (0.75, 0.75, 0.75)

    With saturation put at 1, and lightness put to 0.5, we can find
    normal full red, green, blue colors:

    >>> hsl2rgb((0 , 1.0, 0.5))
    (1.0, 0.0, 0.0)
    >>> hsl2rgb((1 , 1.0, 0.5))
    (1.0, 0.0, 0.0)
    >>> hsl2rgb((1.0/3 , 1.0, 0.5))
    (0.0, 1.0, 0.0)
    >>> hsl2rgb((2.0/3 , 1.0, 0.5))
    (0.0, 0.0, 1.0)

    Of course:
    >>> hsl2rgb((0.0, 2.0, 0.5))  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: Saturation must be between 0 and 1.

    And:
    >>> hsl2rgb((0.0, 0.0, 1.5))  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: Lightness must be between 0 and 1.

    c             S   s   g | ]}t |qS r   )float)r   r   r   r   r   
<listcomp>Z  s    zhsl2rgb.<locals>.<listcomp>g        g      ?z#Saturation must be between 0 and 1.z"Lightness must be between 0 and 1.r   g      ?g       @gUUUUUU?)FLOAT_ERROR
ValueError_hue2rgb)	hslhslv2v1rgbr   r   r   r     s    J
r   c             C   sx  dd | D \}}}xJ|||d  D ]6\}}dt |  krJdt ks&n td||f q&W t|||}t|||}|| }|| }	|	d }
|tk rdd|
fS |
d	k r||	 }n|d
|	  }|| d |d  | }|| d |d  | }|| d |d  | }||kr|| }n.||kr4d| | }n||krJd| | }|dk r\|d7 }|dkrn|d8 }|||
fS )a)  Convert RGB representation towards HSL

    :param r: Red amount (float between 0 and 1)
    :param g: Green amount (float between 0 and 1)
    :param b: Blue amount (float between 0 and 1)
    :rtype: 3-uple for HSL values in float between 0 and 1

    This algorithm came from:
    http://www.easyrgb.com/index.php?X=MATH&H=19#text19

    Here are some quick notion of RGB to HSL conversion:

    >>> from colour import rgb2hsl

    Note that if red amount is equal to green and blue, then you
    should have a gray value (from black to white).


    >>> rgb2hsl((1.0, 1.0, 1.0))  # doctest: +ELLIPSIS
    (..., 0.0, 1.0)
    >>> rgb2hsl((0.5, 0.5, 0.5))  # doctest: +ELLIPSIS
    (..., 0.0, 0.5)
    >>> rgb2hsl((0.0, 0.0, 0.0))  # doctest: +ELLIPSIS
    (..., 0.0, 0.0)

    If only one color is different from the others, it defines the
    direct Hue:

    >>> rgb2hsl((0.5, 0.5, 1.0))  # doctest: +ELLIPSIS
    (0.66..., 1.0, 0.75)
    >>> rgb2hsl((0.2, 0.1, 0.1))  # doctest: +ELLIPSIS
    (0.0, 0.33..., 0.15...)

    Having only one value set, you can check that:

    >>> rgb2hsl((1.0, 0.0, 0.0))
    (0.0, 1.0, 0.5)
    >>> rgb2hsl((0.0, 1.0, 0.0))  # doctest: +ELLIPSIS
    (0.33..., 1.0, 0.5)
    >>> rgb2hsl((0.0, 0.0, 1.0))  # doctest: +ELLIPSIS
    (0.66..., 1.0, 0.5)

    Regression check upon very close values in every component of
    red, green and blue:

    >>> rgb2hsl((0.9999999999999999, 1.0, 0.9999999999999994))
    (0.0, 0.0, 0.999...)

    Of course:

    >>> rgb2hsl((0.0, 2.0, 0.5))  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: Green must be between 0 and 1. You provided 2.0.

    And:
    >>> rgb2hsl((0.0, 0.0, 1.5))  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: Blue must be between 0 and 1. You provided 1.5.

    c             S   s   g | ]}t |qS r   )r   )r   r   r   r   r   r     s    zrgb2hsl.<locals>.<listcomp>)r   r   r   r      z,%s must be between 0 and 1. You provided %r.   g        g      ?g       @   gUUUUUU?gUUUUUU?)itemsr   r   minmax)r   r   r   r   r   r   ZvminZvmaxdiffZvsumr   r   Zdrdgdbr   r   r   r   r   r  s:    ?






 
 r   c             C   s   x|dk r|d7 }qW x|dkr*|d8 }qW d| dk rL| ||  d |  S d| dk r\|S d| dk r| ||  d|  d  S | S )zxPrivate helper function (Do not call directly)

    :param vH: rotation around the chromatic circle (between 0..1)

    r   r   r   r      gUUUUUU?r   )r   r   ZvHr   r   r   r     s    
 
    r   Fc             C   sP   d dd | D }|sH|ddd |ddd krHd |ddd }d| S )	a  Transform RGB tuple to hex RGB representation

    :param rgb: RGB 3-uple of float between 0 and 1
    :rtype: 3 hex char or 6 hex char string representation

    Usage
    -----

    >>> from colour import rgb2hex

    >>> rgb2hex((0.0,1.0,0.0))
    '#0f0'

    Rounding try to be as natural as possible:

    >>> rgb2hex((0.0,0.999999,1.0))
    '#0ff'

    And if not possible, the 6 hex char representation is used:

    >>> rgb2hex((0.23,1.0,1.0))
    '#3bffff'

    >>> rgb2hex((0.0,0.999999,1.0), force_long=True)
    '#00ffff'

     c             S   s$   g | ]}d t |d d t  qS )z%02xr   g      ?)intr   )r   cr   r   r   r     s   zrgb2hex.<locals>.<listcomp>r   Nr   r   z#%s)join)r   
force_longhxr   r   r   r     s
    

 r   c             C   s   y| dd }t |dkrD|dd |dd |dd   }}}n<t |dkrz|d d |d d |d d   }}}nt W n   td|  Y nX td	d
 |||fD S )a  Transform hex RGB representation to RGB tuple

    :param str_rgb: 3 hex char or 6 hex char string representation
    :rtype: RGB 3-uple of float between 0 and 1

    >>> from colour import hex2rgb

    >>> hex2rgb('#00ff00')
    (0.0, 1.0, 0.0)

    >>> hex2rgb('#0f0')
    (0.0, 1.0, 0.0)

    >>> hex2rgb('#aaa')  # doctest: +ELLIPSIS
    (0.66..., 0.66..., 0.66...)

    >>> hex2rgb('#aa')  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: Invalid value '#aa' provided for rgb color.

    r   Nr   r   r      r   z(Invalid value %r provided for rgb color.c             S   s   g | ]}t t|d d qS )   r   )r   r   )r   r   r   r   r   r   :  s    zhex2rgb.<locals>.<listcomp>)lenr   r   )Zstr_rgbr   r   r   r   r   r   r   hex2rgb  s    **
r   c             C   s   t dd t| D }|tkrLt| d }ttdd|dkrD|S | S t| dkr| d | d kr| d	 | d
 kr| d | d krd| d  | d	  | d  S | S )a  Converts HEX representation to WEB

    :param rgb: 3 hex char or 6 hex char string representation
    :rtype: web string representation (human readable if possible)

    WEB representation uses X11 rgb.txt to define conversion
    between RGB and english color names.

    Usage
    =====

    >>> from colour import hex2web

    >>> hex2web('#ff0000')
    'red'

    >>> hex2web('#aaaaaa')
    '#aaa'

    >>> hex2web('#abc')
    '#abc'

    >>> hex2web('#acacac')
    '#acacac'

    c             s   s   | ]}t |d  V  qdS )r   N)r   )r   r   r   r   r   r   X  s    zhex2web.<locals>.<genexpr>r   z[^A-Z]r   r      r   r   r      r   #)r   r   RGB_TO_COLOR_NAMESr   resubr   )hexZdec_rgbZ
color_namer   r   r   hex2web=  s    r   c             C   s   |  drdt| s"|s*t| r*|  S t| rX|rXdddd | dd D  S td|  |  } | tkrtd|  t	d	d t|  D |S )
a%  Converts WEB representation to HEX

    :param rgb: web string representation (human readable if possible)
    :rtype: 3 hex char or 6 hex char string representation

    WEB representation uses X11 rgb.txt to define conversion
    between RGB and english color names.

    Usage
    =====

    >>> from colour import web2hex

    >>> web2hex('red')
    '#f00'

    >>> web2hex('#aaa')
    '#aaa'

    >>> web2hex('#foo')  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    AttributeError: '#foo' is not in web format. Need 3 or 6 hex digit.

    >>> web2hex('#aaa', force_long=True)
    '#aaaaaa'

    >>> web2hex('#aaaaaa')
    '#aaaaaa'

    >>> web2hex('#aaaa')  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    AttributeError: '#aaaa' is not in web format. Need 3 or 6 hex digit.

    >>> web2hex('pinky')  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: 'pinky' is not a recognized color.

    And color names are case insensitive:

    >>> Color('RED')
    <Color red>

    r   r   c             S   s   g | ]}d |f d qS )z%sr   r   )r   tr   r   r   r     s    zweb2hex.<locals>.<listcomp>r   Nz/%r is not in web format. Need 3 or 6 hex digit.z%r is not a recognized color.c             S   s   g | ]}t t|d  qS )r   )r   r   )r   r   r   r   r   r     s    )

startswithLONG_HEX_COLORmatchSHORT_HEX_COLORr   r   r   r   r   r   )webr   r   r   r   web2hexi  s    /

 
r   c             C   s   t t| S )N)r   r   )xr   r   r   <lambda>      r   c             C   s   t t| S )N)r   r   )r   r   r   r   r     r   c             C   s   t t| S )N)r   r   )r   r   r   r   r     r   c             C   s   t t| S )N)r   r   )r   r   r   r   r     r   c             C   s   t t| S )N)r   web2rgb)r   r   r   r   r     r   c             C   s   t t| S )N)rgb2webr   )r   r   r   r   r     r   c                sr   dk rt d dkr<tfddtddD nddd d	d
   fddtdd D S )a  Returns a list of nb color HSL tuples between begin_hsl and end_hsl

    >>> from colour import color_scale

    >>> [rgb2hex(hsl2rgb(hsl)) for hsl in color_scale((0, 1, 0.5),
    ...                                               (1, 1, 0.5), 3)]
    ['#f00', '#0f0', '#00f', '#f00']

    >>> [rgb2hex(hsl2rgb(hsl))
    ...  for hsl in color_scale((0, 0, 0),
    ...                         (0, 0, 1),
    ...                         15)]  # doctest: +ELLIPSIS
    ['#000', '#111', '#222', ..., '#ccc', '#ddd', '#eee', '#fff']

    Of course, asking for negative values is not supported:

    >>> color_scale((0, 1, 0.5), (1, 1, 0.5), -2)
    Traceback (most recent call last):
    ...
    ValueError: Unsupported negative number of colors (nb=-2).

    r   z.Unsupported negative number of colors (nb=%r).c                s$   g | ]}t |  |   qS r   )r   )r   i)	begin_hslend_hslnbr   r   r     s    zcolor_scale.<locals>.<listcomp>r   )r   r   r   c                s   t  fdd| D S )Nc                s   g | ]}|  qS r   r   )r   r   )r   r   r   r     s    z,color_scale.<locals>.mul.<locals>.<listcomp>)r   )stepr   r   )r   r   mul  s    zcolor_scale.<locals>.mulc                s   t  fddt| D S )Nc                s   g | ]\}}| |  qS r   r   )r   r   r   )step2r   r   r     s    z.color_scale.<locals>.add_v.<locals>.<listcomp>)r   	enumerate)r   r   r   )r   r   add_v  s    zcolor_scale.<locals>.add_vc                s   g | ]} |qS r   r   )r   r   )r   r   r   r   r   r   r     s    r   )r   r   range)r   r   r   r   )r   r   r   r   r   r   r   color_scale  s    
,r   c                sp   t t| d  tt d  fddtdD }ttd dfdd|D }t	t
|S )	a  Build a color representation from the string representation of an object

    This allows to quickly get a color from some data, with the
    additional benefit that the color will be the same as long as the
    (string representation of the) data is the same::

        >>> from colour import RGB_color_picker, Color

    Same inputs produce the same result::

        >>> RGB_color_picker("Something") == RGB_color_picker("Something")
        True

    ... but different inputs produce different colors::

        >>> RGB_color_picker("Something") != RGB_color_picker("Something else")
        True

    In any case, we still get a ``Color`` object::

        >>> isinstance(RGB_color_picker("Something"), Color)
        True

    zutf-8r   c                s$   g | ]} | |d    qS )r   r   )r   r   )digestsubsizer   r   r     s   z$RGB_color_picker.<locals>.<listcomp>fr   c             3   s   | ]}t |d   V  qdS )r   N)r   )r   d)	max_valuer   r   r   	  s   z#RGB_color_picker.<locals>.<genexpr>)hashlibsha384strencode	hexdigestr   r   r   r   Colorr   )objZsplitted_digest
componentsr   )r   r   r   r   RGB_color_picker  s    
r   c             C   s:   yt t| j| fS  tk
r4   t| jt|  S X d S )N)hashtyper   	TypeErrorr   )r   r   r   r   hash_or_str  s    r   c               @   s  e Zd ZdZdZddeefd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 Zd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& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 ZeZd1d2 Zd3d4 Z d5d6 Z!d7d8 Z"d9d: Z#e$j%d; d<krd=d> Z&dS )?r   aQ  Abstraction of a color object

    Color object keeps information of a color. It can input/output to different
    format (HSL, RGB, HEX, WEB) and their partial representation.

        >>> from colour import Color, HSL

        >>> b = Color()
        >>> b.hsl = HSL.BLUE

    Access values
    -------------

        >>> b.hue  # doctest: +ELLIPSIS
        0.66...
        >>> b.saturation
        1.0
        >>> b.luminance
        0.5

        >>> b.red
        0.0
        >>> b.blue
        1.0
        >>> b.green
        0.0

        >>> b.rgb
        (0.0, 0.0, 1.0)
        >>> b.hsl  # doctest: +ELLIPSIS
        (0.66..., 1.0, 0.5)
        >>> b.hex
        '#00f'

    Change values
    -------------

    Let's change Hue toward red tint:

        >>> b.hue = 0.0
        >>> b.hex
        '#f00'

        >>> b.hue = 2.0/3
        >>> b.hex
        '#00f'

    In the other way round:

        >>> b.hex = '#f00'
        >>> b.hsl
        (0.0, 1.0, 0.5)

    Long hex can be accessed directly:

        >>> b.hex_l = '#123456'
        >>> b.hex_l
        '#123456'
        >>> b.hex
        '#123456'

        >>> b.hex_l = '#ff0000'
        >>> b.hex_l
        '#ff0000'
        >>> b.hex
        '#f00'

    Convenience
    -----------

        >>> c = Color('blue')
        >>> c
        <Color blue>
        >>> c.hue = 0
        >>> c
        <Color red>

        >>> c.saturation = 0.0
        >>> c.hsl  # doctest: +ELLIPSIS
        (..., 0.0, 0.5)
        >>> c.rgb
        (0.5, 0.5, 0.5)
        >>> c.hex
        '#7f7f7f'
        >>> c
        <Color #7f7f7f>

        >>> c.luminance = 0.0
        >>> c
        <Color black>

        >>> c.hex
        '#000'

        >>> c.green = 1.0
        >>> c.blue = 1.0
        >>> c.hex
        '#0ff'
        >>> c
        <Color cyan>

        >>> c = Color('blue', luminance=0.75)
        >>> c
        <Color #7f7fff>

        >>> c = Color('red', red=0.5)
        >>> c
        <Color #7f0000>

        >>> print(c)
        #7f0000

    You can try to query unexisting attributes:

        >>> c.lightness  # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        AttributeError: 'lightness' not found

    TODO: could add HSV, CMYK, YUV conversion.

#     >>> b.hsv
#     >>> b.value
#     >>> b.cyan
#     >>> b.magenta
#     >>> b.yellow
#     >>> b.key
#     >>> b.cmyk


    Recursive init
    --------------

    To support blind conversion of web strings (or already converted object),
    the Color object supports instantiation with another Color object.

        >>> Color(Color(Color('red')))
        <Color red>

    Equality support
    ----------------

    Default equality is RGB hex comparison:

        >>> Color('red') == Color('blue')
        False
        >>> Color('red') == Color('red')
        True
        >>> Color('red') != Color('blue')
        True
        >>> Color('red') != Color('red')
        False

    But this can be changed:

        >>> saturation_equality = lambda c1, c2: c1.luminance == c2.luminance
        >>> Color('red', equality=saturation_equality) == Color('blue')
        True


    Subclassing support
    -------------------

    You should be able to subclass ``Color`` object without any issues::

        >>> class Tint(Color):
        ...     pass

    And keep the internal API working::

        >>> Tint("red").hsl
        (0.0, 1.0, 0.5)

    Nc             K   sr   |d krdd }|d k	r$|||}t |tr8|j| _n|r@|nd| _t| _x | D ]\}}t| || qVW d S )Nc             S   s   | S )Nr   )r   r   r   r   r     r   z Color.__init__.<locals>.<lambda>black)
isinstancer   r   RGB_equivalenceequalityr   setattr)r   colorZpick_forZpickerZpick_keykwargskr   r   r   r   __init__  s    

zColor.__init__c             C   sL   | drtd| yt| d|  S  tk
rF   td| Y nX d S )Nget_z'%s' not found)r   r   r   )r   r   r   r   r   r     s    
zColor.__getattr__c             C   s.   |dkr t | d| }|| n
|| j|< d S )N)_hslr  set_)r   __dict__)r   r   r   Zfcr   r   r   __setattr__  s    
zColor.__setattr__c             C   s
   t | jS )N)r   r  )r   r   r   r   get_hsl  s    zColor.get_hslc             C   s
   t | jS )N)r   r   )r   r   r   r   get_hex  s    zColor.get_hexc             C   s   t | jddS )NT)r   )r   r   )r   r   r   r   	get_hex_l  s    zColor.get_hex_lc             C   s
   t | jS )N)r   r   )r   r   r   r   get_rgb  s    zColor.get_rgbc             C   s
   | j d S )Nr   )r   )r   r   r   r   get_hue  s    zColor.get_huec             C   s
   | j d S )Nr   )r   )r   r   r   r   get_saturation  s    zColor.get_saturationc             C   s
   | j d S )Nr   )r   )r   r   r   r   get_luminance  s    zColor.get_luminancec             C   s
   | j d S )Nr   )r   )r   r   r   r   get_red  s    zColor.get_redc             C   s
   | j d S )Nr   )r   )r   r   r   r   	get_green  s    zColor.get_greenc             C   s
   | j d S )Nr   )r   )r   r   r   r   get_blue  s    zColor.get_bluec             C   s
   t | jS )N)r   r   )r   r   r   r   get_web  s    zColor.get_webc             C   s   t || _d S )N)listr  )r   r   r   r   r   set_hsl  s    zColor.set_hslc             C   s   t || _d S )N)r   r   )r   r   r   r   r   set_rgb  s    zColor.set_rgbc             C   s   || j d< d S )Nr   )r  )r   r   r   r   r   set_hue!  s    zColor.set_huec             C   s   || j d< d S )Nr   )r  )r   r   r   r   r   set_saturation$  s    zColor.set_saturationc             C   s   || j d< d S )Nr   )r  )r   r   r   r   r   set_luminance'  s    zColor.set_luminancec             C   s   | j \}}}|||f| _ d S )N)r   )r   r   _r   r   r   r   r   set_red*  s    zColor.set_redc             C   s   | j \}}}|||f| _ d S )N)r   )r   r   r   r  r   r   r   r   	set_green.  s    zColor.set_greenc             C   s   | j \}}}|||f| _ d S )N)r   )r   r   r   r   r  r   r   r   set_blue2  s    zColor.set_bluec             C   s   t || _d S )N)r   r   )r   r   r   r   r   set_hex6  s    zColor.set_hexc             C   s   t || _d S )N)r   r   )r   r   r   r   r   set_web;  s    zColor.set_webc             c   s2   x,t | jt|j|d D ]}t|dV  qW d S )Nr   )r   )r   r  r   r   )r   r   Zstepsr   r   r   r   range_to@  s    zColor.range_toc             C   s
   d| j  S )Nz%s)r   )r   r   r   r   __str__H  s    zColor.__str__c             C   s
   d| j  S )Nz
<Color %s>)r   )r   r   r   r   __repr__K  s    zColor.__repr__c             C   s   t |tr| | |S tS )N)r   r   r  NotImplemented)r   otherr   r   r   __eq__N  s    
zColor.__eq__r   r   c             C   s   |  |}|tkr|S | S )N)r(  r&  )r   r'  equalr   r   r   __ne__U  s    
zColor.__ne__)'r   r   r   r   r  r   r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  Z	set_hex_lr"  r#  r$  r%  r(  sysversion_infor*  r   r   r   r   r     sF    /r   c             C   s   | j |j kS )N)Zhex_l)c1c2r   r   r   r   Z  r   c             C   s   | j |j kS )N)r  )r-  r.  r   r   r   r   [  r   c                 s    fdd}|S )Nc                 s      }|| t| |S )N)copyupdater   )argsr  Z
new_kwargs)kwargs_defaultsr   r   ColorFactory`  s    
z(make_color_factory.<locals>.ColorFactoryr   )r2  r3  r   )r2  r   make_color_factory^  s    r4  )F)F)*r   
__future__r   r   r   r   r+  r   r   dictr   r   compiler   r   r   r   r   r   r   HEXr   r   r   r   r   r   r   Zhsl2hexZhex2hslr   r   Zweb2hslZhsl2webr   r   r   objectr   r   ZHSL_equivalencer4  r   r   r   r   <module>#   sd  



bl
&(,
D,/  ?