colour


Namecolour JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttp://github.com/vaab/colour
Summaryconverts and manipulates various color representation (HSL, RVB, web, X11, ...)
upload_time2017-11-19 23:20:08
maintainer
docs_urlNone
authorValentin LAB
requires_python
licenseBSD 3-Clause License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ======
Colour
======

.. image:: http://img.shields.io/pypi/v/colour.svg?style=flat
   :target: https://pypi.python.org/pypi/colour/
   :alt: Latest PyPI version

.. image:: https://img.shields.io/pypi/l/gitchangelog.svg?style=flat
   :target: https://github.com/vaab/gitchangelog/blob/master/LICENSE
   :alt: License

.. image:: https://img.shields.io/pypi/pyversions/gitchangelog.svg?style=flat
   :target: https://pypi.python.org/pypi/gitchangelog/
   :alt: Compatible python versions

.. image:: http://img.shields.io/pypi/dm/colour.svg?style=flat
   :target: https://pypi.python.org/pypi/colour/
   :alt: Number of PyPI downloads

.. image:: http://img.shields.io/travis/vaab/colour/master.svg?style=flat
   :target: https://travis-ci.org/vaab/colour/
   :alt: Travis CI build status

.. image:: https://img.shields.io/appveyor/ci/vaab/colour.svg
   :target: https://ci.appveyor.com/project/vaab/colour/branch/master
   :alt: Appveyor CI build status

.. image:: http://img.shields.io/codecov/c/github/vaab/colour.svg?style=flat
   :target: https://codecov.io/gh/vaab/colour/
   :alt: Test coverage


Converts and manipulates common color representation (RGB, HSL, web, ...)


Feature
=======

- Damn simple and pythonic way to manipulate color representation (see
  examples below)

- Full conversion between RGB, HSL, 6-digit hex, 3-digit hex, human color

- One object (``Color``) or bunch of single purpose function (``rgb2hex``,
  ``hsl2rgb`` ...)

- ``web`` format that use the smallest representation between
  6-digit (e.g. ``#fa3b2c``), 3-digit (e.g. ``#fbb``), fully spelled
  color (e.g. ``white``), following `W3C color naming`_ for compatible
  CSS or HTML color specifications.

- smooth intuitive color scale generation choosing N color gradients.

- can pick colors for you to identify objects of your application.


.. _W3C color naming: http://www.w3.org/TR/css3-color/#svg-color


Installation
============

You don't need to download the GIT version of the code as ``colour`` is
available on the PyPI. So you should be able to run::

    pip install colour

If you have downloaded the GIT sources, then you could add the ``colour.py``
directly to one of your ``site-packages`` (thanks to a symlink). Or install
the current version via traditional::

    python setup.py install

And if you don't have the GIT sources but would like to get the latest
master or branch from github, you could also::

    pip install git+https://github.com/vaab/colour

Or even select a specific revision (branch/tag/commit)::

    pip install git+https://github.com/vaab/colour@master


Usage
=====

To get complete demo of each function, please read the source code which is
heavily documented and provide a lot of examples in doctest format.

Here is a reduced sample of a common usage scenario:


Instantiation
-------------

Let's create blue color::

    >>> from colour import Color
    >>> c = Color("blue")
    >>> c
    <Color blue>

Please note that all of these are equivalent examples to create the red color::

    Color("red")           ## human, web compatible representation
    Color(red=1)           ## default amount of blue and green is 0.0
    Color("blue", hue=0)   ## hue of blue is 0.66, hue of red is 0.0
    Color("#f00")          ## standard 3 hex digit web compatible representation
    Color("#ff0000")       ## standard 6 hex digit web compatible representation
    Color(hue=0, saturation=1, luminance=0.5)
    Color(hsl=(0, 1, 0.5)) ## full 3-uple HSL specification
    Color(rgb=(1, 0, 0))   ## full 3-uple RGB specification
    Color(Color("red"))    ## recursion doesn't break object


Reading values
--------------

Several representations are accessible::

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

And their different parts are also independently accessible, as the different
amount of red, blue, green, in the RGB format::

    >>> c.red
    0.0
    >>> c.blue
    1.0
    >>> c.green
    0.0

Or the hue, saturation and luminance of the HSL representation::

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

A note on the ``.hex`` property, it'll return the smallest valid value
when possible. If you are only interested by the long value, use
``.hex_l``::

    >>> c.hex_l
    '#0000ff'


Modifying color objects
-----------------------

All of these properties are read/write, so let's add some red to this color::

    >>> c.red = 1
    >>> c
    <Color magenta>

We might want to de-saturate this color::

    >>> c.saturation = 0.5
    >>> c
    <Color #bf40bf>

And of course, the string conversion will give the web representation which is
human, or 3-digit, or 6-digit hex representation depending which is usable::

    >>> "%s" % c
    '#bf40bf'

    >>> c.luminance = 1
    >>> "%s" % c
    'white'


Ranges of colors
----------------

You can get some color scale of variation between two ``Color`` objects quite
easily. Here, is the color scale of the rainbow between red and blue::

    >>> red = Color("red")
    >>> blue = Color("blue")
    >>> list(red.range_to(blue, 5))
    [<Color red>, <Color yellow>, <Color lime>, <Color cyan>, <Color blue>]

Or the different amount of gray between black and white::

    >>> black = Color("black")
    >>> white = Color("white")
    >>> list(black.range_to(white, 6))
    [<Color black>, <Color #333>, <Color #666>, <Color #999>, <Color #ccc>, <Color white>]


If you have to create graphical representation with color scale
between red and green ('lime' color is full green)::

    >>> lime = Color("lime")
    >>> list(red.range_to(lime, 5))
    [<Color red>, <Color #ff7f00>, <Color yellow>, <Color chartreuse>, <Color lime>]

Notice how naturally, the yellow is displayed in human format and in
the middle of the scale. And that the quite unusual (but compatible)
'chartreuse' color specification has been used in place of the
hexadecimal representation.


Color comparison
----------------

Sane default
~~~~~~~~~~~~

Color comparison is a vast subject. However, it might seem quite straightforward for
you. ``Colour`` uses a configurable default way of comparing color that might suit
your needs::

    >>> Color("red") == Color("#f00") == Color("blue", hue=0)
    True

The default comparison algorithm focuses only on the "web" representation which is
equivalent to comparing the long hex representation (e.g. #FF0000) or to be more
specific, it is equivalent to compare the amount of red, green, and blue composition
of the RGB representation, each of these value being quantized to a 256 value scale.

This default comparison is a practical and convenient way to measure the actual
color equivalence on your screen, or in your video card memory.

But this comparison wouldn't make the difference between a black red, and a
black blue, which both are black::

   >>> black_red = Color("red", luminance=0)
   >>> black_blue = Color("blue", luminance=0)

   >>> black_red == black_blue
   True


Customization
~~~~~~~~~~~~~

But, this is not the sole way to compare two colors. As I'm quite lazy, I'm providing
you a way to customize it to your needs. Thus::

   >>> from colour import RGB_equivalence, HSL_equivalence
   >>> black_red = Color("red", luminance=0, equality=HSL_equivalence)
   >>> black_blue = Color("blue", luminance=0, equality=HSL_equivalence)

   >>> black_red == black_blue
   False

As you might have already guessed, the sane default is ``RGB_equivalence``, so::

   >>> black_red = Color("red", luminance=0, equality=RGB_equivalence)
   >>> black_blue = Color("blue", luminance=0, equality=RGB_equivalence)

   >>> black_red == black_blue
   True

Here's how you could implement your unique comparison function::

   >>> saturation_equivalence = lambda c1, c2: c1.saturation == c2.saturation
   >>> red = Color("red", equality=saturation_equivalence)
   >>> blue = Color("blue", equality=saturation_equivalence)
   >>> white = Color("white", equality=saturation_equivalence)

   >>> red == blue
   True
   >>> white == red
   False

Note: When comparing 2 colors, *only* the equality function *of the first
color will be used*. Thus::

   >>> black_red = Color("red", luminance=0, equality=RGB_equivalence)
   >>> black_blue = Color("blue", luminance=0, equality=HSL_equivalence)

   >>> black_red == black_blue
   True

But reverse operation is not equivalent !::

   >>> black_blue == black_red
   False


Equality to non-Colour objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As a side note, whatever your custom equality function is, it won't be
used if you compare to anything else than a ``Colour`` instance::

    >>> red = Color("red", equality=lambda c1, c2: True)
    >>> blue = Color("blue", equality=lambda c1, c2: True)

Note that these instances would compare as equal to any other color::

    >>> red == blue
    True

But on another non-Colour object::

    >>> red == None
    False
    >>> red != None
    True

Actually, ``Colour`` instances will, politely enough, leave
the other side of the equality have a chance to decide of the output,
(by executing its own ``__eq__``), so::

    >>> class OtherColorImplem(object):
    ...     def __init__(self, color):
    ...         self.color = color
    ...     def __eq__(self, other):
    ...         return self.color == other.web

    >>> alien_red = OtherColorImplem("red")
    >>> red == alien_red
    True
    >>> blue == alien_red
    False

And inequality (using ``__ne__``) are also polite::

    >>> class AnotherColorImplem(OtherColorImplem):
    ...     def __ne__(self, other):
    ...         return self.color != other.web

    >>> new_alien_red = AnotherColorImplem("red")
    >>> red != new_alien_red
    False
    >>> blue != new_alien_red
    True


Picking arbitrary color for a python object
-------------------------------------------

Basic Usage
~~~~~~~~~~~

Sometimes, you just want to pick a color for an object in your application
often to visually identify this object. Thus, the picked color should be the
same for same objects, and different for different object::

    >>> foo = object()
    >>> bar = object()

    >>> Color(pick_for=foo)  # doctest: +ELLIPSIS
    <Color ...>
    >>> Color(pick_for=foo) == Color(pick_for=foo)
    True
    >>> Color(pick_for=foo) == Color(pick_for=bar)
    False

Of course, although there's a tiny probability that different strings yield the
same color, most of the time, different inputs will produce different colors.

Advanced Usage
~~~~~~~~~~~~~~

You can customize your color picking algorithm by providing a ``picker``. A
``picker`` is a callable that takes an object, and returns something that can
be instantiated as a color by ``Color``::

    >>> my_picker = lambda obj: "red" if isinstance(obj, int) else "blue"
    >>> Color(pick_for=3, picker=my_picker, pick_key=None)
    <Color red>
    >>> Color(pick_for="foo", picker=my_picker, pick_key=None)
    <Color blue>

You might want to use a particular picker, but enforce how the picker will
identify two object as the same (or not). So there's a ``pick_key`` attribute
that is provided and defaults as equivalent of ``hash`` method and if hash is
not supported by your object, it'll default to the ``str`` of your object salted
with the class name.

Thus::

    >>> class MyObj(str): pass
    >>> my_obj_color = Color(pick_for=MyObj("foo"))
    >>> my_str_color = Color(pick_for="foo")
    >>> my_obj_color == my_str_color
    False

Please make sure your object is hashable or "stringable" before using the
``RGB_color_picker`` picking mechanism or provide another color picker. Nearly
all python object are hashable by default so this shouldn't be an issue (e.g. 
instances of ``object`` and subclasses are hashable).

Neither ``hash`` nor ``str`` are perfect solution. So feel free to use
``pick_key`` at ``Color`` instantiation time to set your way to identify
objects, for instance::

    >>> a = object()
    >>> b = object()
    >>> Color(pick_for=a, pick_key=id) == Color(pick_for=b, pick_key=id)
    False

When choosing a pick key, you should closely consider if you want your color
to be consistent between runs (this is NOT the case with the last example),
or consistent with the content of your object if it is a mutable object.

Default value of ``pick_key`` and ``picker`` ensures that the same color will
be attributed to same object between different run on different computer for
most python object.


Color factory
-------------

As you might have noticed, there are few attributes that you might want to see
attached to all of your colors as ``equality`` for equality comparison support,
or ``picker``, ``pick_key`` to configure your object color picker.

You can create a customized ``Color`` factory thanks to the ``make_color_factory``::

    >>> from colour import make_color_factory, HSL_equivalence, RGB_color_picker

    >>> get_color = make_color_factory(
    ...    equality=HSL_equivalence,
    ...    picker=RGB_color_picker,
    ...    pick_key=str,
    ... )

All color created thanks to ``CustomColor`` class instead of the default one
would get the specified attributes by default::

    >>> black_red = get_color("red", luminance=0)
    >>> black_blue = get_color("blue", luminance=0)

Of course, these are always instances of ``Color`` class::

    >>> isinstance(black_red, Color)
    True

Equality was changed from normal defaults, so::

    >>> black_red == black_blue
    False

This because the default equivalence of ``Color`` was set to
``HSL_equivalence``.


Contributing
============

Any suggestion or issue is welcome. Push request are very welcome,
please check out the guidelines.


Push Request Guidelines
-----------------------

You can send any code. I'll look at it and will integrate it myself in
the code base and leave you as the author. This process can take time and
it'll take less time if you follow the following guidelines:

- check your code with PEP8 or pylint. Try to stick to 80 columns wide.
- separate your commits per smallest concern.
- each commit should pass the tests (to allow easy bisect)
- each functionality/bugfix commit should contain the code, tests,
  and doc.
- prior minor commit with typographic or code cosmetic changes are
  very welcome. These should be tagged in their commit summary with
  ``!minor``.
- the commit message should follow gitchangelog rules (check the git
  log to get examples)
- if the commit fixes an issue or finished the implementation of a
  feature, please mention it in the summary.

If you have some questions about guidelines which is not answered here,
please check the current ``git log``, you might find previous commit that
would show you how to deal with your issue.


License
=======

Copyright (c) 2012-2017 Valentin Lab.

Licensed under the `BSD License`_.

.. _BSD License: http://raw.github.com/vaab/colour/master/LICENSE

Changelog
=========


0.1.4 (2017-04-19)
------------------

Fix
~~~
- ``rgb2hsl`` would produce invalid hsl triplet when red, blue, green
  component would be all very close to ``1.0``. (fixes #30) [Valentin
  Lab]

  Typically, saturation would shoot out of range 0.0..1.0. That could then
  lead to exceptions being casts afterwards when trying to reconvert this
  HSL triplet to RGB values.


0.1.3 (2017-04-08)
------------------

Fix
~~~
- Unexpected behavior with ``!=`` operator. (fixes #26) [Valentin Lab]
- Added mention of the ``hex_l`` property. (fixes #27) [Valentin Lab]


0.1.2 (2015-09-15)
------------------

Fix
~~~
- Support for corner case 1-wide ``range_to`` color scale. (fixes #18)
  [Valentin Lab]


0.1.1 (2015-03-29)
------------------

Fix
~~~
- Avoid casting an exception when comparing to non-``Colour`` instances.
  (fixes #14) [Riziq Sayegh]


0.0.6 (2014-11-18)
------------------

New
~~~
- Provide all missing *2* function by combination with other existing
  ones (fixes #13). [Valentin Lab]
- Provide full access to any color name in HSL, RGB, HEX convenience
  instances. [Valentin Lab]

  Now you can call ``colour.HSL.cyan``, or ``colour.HEX.red`` for a direct encoding of
  ``human`` colour labels to the 3 representations.


0.0.5 (2013-09-16)
------------------

New
~~~
- Color names are case insensitive. [Chris Priest]

  The color-name structure have their names capitalized. And color names
  that are made of only one word will be displayed lowercased.

Fix
~~~
- Now using W3C color recommandation. [Chris Priest]

  Was using X11 color scheme before, which is slightly different from
  W3C web color specifications.
- Inconsistency in licence information (removed GPL mention). (fixes #8)
  [Valentin Lab]
- Removed ``gitchangelog`` from ``setup.py`` require list. (fixes #9)
  [Valentin Lab]


0.0.4 (2013-06-21)
------------------

New
~~~
- Added ``make_color_factory`` to customize some common color
  attributes. [Valentin Lab]
- Pick color to identify any python object (fixes #6) [Jonathan Ballet]
- Equality support between colors, customizable if needed. (fixes #3)
  [Valentin Lab]


0.0.3 (2013-06-19)
------------------

New
~~~
- Colour is now compatible with python3. [Ryan Leckey]


0.0.1 (2012-06-11)
------------------
- First import. [Valentin Lab]

TODO
====

- ANSI 16-color and 256-color escape sequence generation
- YUV, HSV, CMYK support




            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/vaab/colour",
    "name": "colour",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Valentin LAB",
    "author_email": "valentin.lab@kalysto.org",
    "download_url": "https://files.pythonhosted.org/packages/a0/d4/5911a7618acddc3f594ddf144ecd8a03c29074a540f4494670ad8f153efe/colour-0.1.5.tar.gz",
    "platform": "",
    "description": "======\nColour\n======\n\n.. image:: http://img.shields.io/pypi/v/colour.svg?style=flat\n   :target: https://pypi.python.org/pypi/colour/\n   :alt: Latest PyPI version\n\n.. image:: https://img.shields.io/pypi/l/gitchangelog.svg?style=flat\n   :target: https://github.com/vaab/gitchangelog/blob/master/LICENSE\n   :alt: License\n\n.. image:: https://img.shields.io/pypi/pyversions/gitchangelog.svg?style=flat\n   :target: https://pypi.python.org/pypi/gitchangelog/\n   :alt: Compatible python versions\n\n.. image:: http://img.shields.io/pypi/dm/colour.svg?style=flat\n   :target: https://pypi.python.org/pypi/colour/\n   :alt: Number of PyPI downloads\n\n.. image:: http://img.shields.io/travis/vaab/colour/master.svg?style=flat\n   :target: https://travis-ci.org/vaab/colour/\n   :alt: Travis CI build status\n\n.. image:: https://img.shields.io/appveyor/ci/vaab/colour.svg\n   :target: https://ci.appveyor.com/project/vaab/colour/branch/master\n   :alt: Appveyor CI build status\n\n.. image:: http://img.shields.io/codecov/c/github/vaab/colour.svg?style=flat\n   :target: https://codecov.io/gh/vaab/colour/\n   :alt: Test coverage\n\n\nConverts and manipulates common color representation (RGB, HSL, web, ...)\n\n\nFeature\n=======\n\n- Damn simple and pythonic way to manipulate color representation (see\n  examples below)\n\n- Full conversion between RGB, HSL, 6-digit hex, 3-digit hex, human color\n\n- One object (``Color``) or bunch of single purpose function (``rgb2hex``,\n  ``hsl2rgb`` ...)\n\n- ``web`` format that use the smallest representation between\n  6-digit (e.g. ``#fa3b2c``), 3-digit (e.g. ``#fbb``), fully spelled\n  color (e.g. ``white``), following `W3C color naming`_ for compatible\n  CSS or HTML color specifications.\n\n- smooth intuitive color scale generation choosing N color gradients.\n\n- can pick colors for you to identify objects of your application.\n\n\n.. _W3C color naming: http://www.w3.org/TR/css3-color/#svg-color\n\n\nInstallation\n============\n\nYou don't need to download the GIT version of the code as ``colour`` is\navailable on the PyPI. So you should be able to run::\n\n    pip install colour\n\nIf you have downloaded the GIT sources, then you could add the ``colour.py``\ndirectly to one of your ``site-packages`` (thanks to a symlink). Or install\nthe current version via traditional::\n\n    python setup.py install\n\nAnd if you don't have the GIT sources but would like to get the latest\nmaster or branch from github, you could also::\n\n    pip install git+https://github.com/vaab/colour\n\nOr even select a specific revision (branch/tag/commit)::\n\n    pip install git+https://github.com/vaab/colour@master\n\n\nUsage\n=====\n\nTo get complete demo of each function, please read the source code which is\nheavily documented and provide a lot of examples in doctest format.\n\nHere is a reduced sample of a common usage scenario:\n\n\nInstantiation\n-------------\n\nLet's create blue color::\n\n    >>> from colour import Color\n    >>> c = Color(\"blue\")\n    >>> c\n    <Color blue>\n\nPlease note that all of these are equivalent examples to create the red color::\n\n    Color(\"red\")           ## human, web compatible representation\n    Color(red=1)           ## default amount of blue and green is 0.0\n    Color(\"blue\", hue=0)   ## hue of blue is 0.66, hue of red is 0.0\n    Color(\"#f00\")          ## standard 3 hex digit web compatible representation\n    Color(\"#ff0000\")       ## standard 6 hex digit web compatible representation\n    Color(hue=0, saturation=1, luminance=0.5)\n    Color(hsl=(0, 1, 0.5)) ## full 3-uple HSL specification\n    Color(rgb=(1, 0, 0))   ## full 3-uple RGB specification\n    Color(Color(\"red\"))    ## recursion doesn't break object\n\n\nReading values\n--------------\n\nSeveral representations are accessible::\n\n    >>> c.hex\n    '#00f'\n    >>> c.hsl  # doctest: +ELLIPSIS\n    (0.66..., 1.0, 0.5)\n    >>> c.rgb\n    (0.0, 0.0, 1.0)\n\nAnd their different parts are also independently accessible, as the different\namount of red, blue, green, in the RGB format::\n\n    >>> c.red\n    0.0\n    >>> c.blue\n    1.0\n    >>> c.green\n    0.0\n\nOr the hue, saturation and luminance of the HSL representation::\n\n    >>> c.hue  # doctest: +ELLIPSIS\n    0.66...\n    >>> c.saturation\n    1.0\n    >>> c.luminance\n    0.5\n\nA note on the ``.hex`` property, it'll return the smallest valid value\nwhen possible. If you are only interested by the long value, use\n``.hex_l``::\n\n    >>> c.hex_l\n    '#0000ff'\n\n\nModifying color objects\n-----------------------\n\nAll of these properties are read/write, so let's add some red to this color::\n\n    >>> c.red = 1\n    >>> c\n    <Color magenta>\n\nWe might want to de-saturate this color::\n\n    >>> c.saturation = 0.5\n    >>> c\n    <Color #bf40bf>\n\nAnd of course, the string conversion will give the web representation which is\nhuman, or 3-digit, or 6-digit hex representation depending which is usable::\n\n    >>> \"%s\" % c\n    '#bf40bf'\n\n    >>> c.luminance = 1\n    >>> \"%s\" % c\n    'white'\n\n\nRanges of colors\n----------------\n\nYou can get some color scale of variation between two ``Color`` objects quite\neasily. Here, is the color scale of the rainbow between red and blue::\n\n    >>> red = Color(\"red\")\n    >>> blue = Color(\"blue\")\n    >>> list(red.range_to(blue, 5))\n    [<Color red>, <Color yellow>, <Color lime>, <Color cyan>, <Color blue>]\n\nOr the different amount of gray between black and white::\n\n    >>> black = Color(\"black\")\n    >>> white = Color(\"white\")\n    >>> list(black.range_to(white, 6))\n    [<Color black>, <Color #333>, <Color #666>, <Color #999>, <Color #ccc>, <Color white>]\n\n\nIf you have to create graphical representation with color scale\nbetween red and green ('lime' color is full green)::\n\n    >>> lime = Color(\"lime\")\n    >>> list(red.range_to(lime, 5))\n    [<Color red>, <Color #ff7f00>, <Color yellow>, <Color chartreuse>, <Color lime>]\n\nNotice how naturally, the yellow is displayed in human format and in\nthe middle of the scale. And that the quite unusual (but compatible)\n'chartreuse' color specification has been used in place of the\nhexadecimal representation.\n\n\nColor comparison\n----------------\n\nSane default\n~~~~~~~~~~~~\n\nColor comparison is a vast subject. However, it might seem quite straightforward for\nyou. ``Colour`` uses a configurable default way of comparing color that might suit\nyour needs::\n\n    >>> Color(\"red\") == Color(\"#f00\") == Color(\"blue\", hue=0)\n    True\n\nThe default comparison algorithm focuses only on the \"web\" representation which is\nequivalent to comparing the long hex representation (e.g. #FF0000) or to be more\nspecific, it is equivalent to compare the amount of red, green, and blue composition\nof the RGB representation, each of these value being quantized to a 256 value scale.\n\nThis default comparison is a practical and convenient way to measure the actual\ncolor equivalence on your screen, or in your video card memory.\n\nBut this comparison wouldn't make the difference between a black red, and a\nblack blue, which both are black::\n\n   >>> black_red = Color(\"red\", luminance=0)\n   >>> black_blue = Color(\"blue\", luminance=0)\n\n   >>> black_red == black_blue\n   True\n\n\nCustomization\n~~~~~~~~~~~~~\n\nBut, this is not the sole way to compare two colors. As I'm quite lazy, I'm providing\nyou a way to customize it to your needs. Thus::\n\n   >>> from colour import RGB_equivalence, HSL_equivalence\n   >>> black_red = Color(\"red\", luminance=0, equality=HSL_equivalence)\n   >>> black_blue = Color(\"blue\", luminance=0, equality=HSL_equivalence)\n\n   >>> black_red == black_blue\n   False\n\nAs you might have already guessed, the sane default is ``RGB_equivalence``, so::\n\n   >>> black_red = Color(\"red\", luminance=0, equality=RGB_equivalence)\n   >>> black_blue = Color(\"blue\", luminance=0, equality=RGB_equivalence)\n\n   >>> black_red == black_blue\n   True\n\nHere's how you could implement your unique comparison function::\n\n   >>> saturation_equivalence = lambda c1, c2: c1.saturation == c2.saturation\n   >>> red = Color(\"red\", equality=saturation_equivalence)\n   >>> blue = Color(\"blue\", equality=saturation_equivalence)\n   >>> white = Color(\"white\", equality=saturation_equivalence)\n\n   >>> red == blue\n   True\n   >>> white == red\n   False\n\nNote: When comparing 2 colors, *only* the equality function *of the first\ncolor will be used*. Thus::\n\n   >>> black_red = Color(\"red\", luminance=0, equality=RGB_equivalence)\n   >>> black_blue = Color(\"blue\", luminance=0, equality=HSL_equivalence)\n\n   >>> black_red == black_blue\n   True\n\nBut reverse operation is not equivalent !::\n\n   >>> black_blue == black_red\n   False\n\n\nEquality to non-Colour objects\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nAs a side note, whatever your custom equality function is, it won't be\nused if you compare to anything else than a ``Colour`` instance::\n\n    >>> red = Color(\"red\", equality=lambda c1, c2: True)\n    >>> blue = Color(\"blue\", equality=lambda c1, c2: True)\n\nNote that these instances would compare as equal to any other color::\n\n    >>> red == blue\n    True\n\nBut on another non-Colour object::\n\n    >>> red == None\n    False\n    >>> red != None\n    True\n\nActually, ``Colour`` instances will, politely enough, leave\nthe other side of the equality have a chance to decide of the output,\n(by executing its own ``__eq__``), so::\n\n    >>> class OtherColorImplem(object):\n    ...     def __init__(self, color):\n    ...         self.color = color\n    ...     def __eq__(self, other):\n    ...         return self.color == other.web\n\n    >>> alien_red = OtherColorImplem(\"red\")\n    >>> red == alien_red\n    True\n    >>> blue == alien_red\n    False\n\nAnd inequality (using ``__ne__``) are also polite::\n\n    >>> class AnotherColorImplem(OtherColorImplem):\n    ...     def __ne__(self, other):\n    ...         return self.color != other.web\n\n    >>> new_alien_red = AnotherColorImplem(\"red\")\n    >>> red != new_alien_red\n    False\n    >>> blue != new_alien_red\n    True\n\n\nPicking arbitrary color for a python object\n-------------------------------------------\n\nBasic Usage\n~~~~~~~~~~~\n\nSometimes, you just want to pick a color for an object in your application\noften to visually identify this object. Thus, the picked color should be the\nsame for same objects, and different for different object::\n\n    >>> foo = object()\n    >>> bar = object()\n\n    >>> Color(pick_for=foo)  # doctest: +ELLIPSIS\n    <Color ...>\n    >>> Color(pick_for=foo) == Color(pick_for=foo)\n    True\n    >>> Color(pick_for=foo) == Color(pick_for=bar)\n    False\n\nOf course, although there's a tiny probability that different strings yield the\nsame color, most of the time, different inputs will produce different colors.\n\nAdvanced Usage\n~~~~~~~~~~~~~~\n\nYou can customize your color picking algorithm by providing a ``picker``. A\n``picker`` is a callable that takes an object, and returns something that can\nbe instantiated as a color by ``Color``::\n\n    >>> my_picker = lambda obj: \"red\" if isinstance(obj, int) else \"blue\"\n    >>> Color(pick_for=3, picker=my_picker, pick_key=None)\n    <Color red>\n    >>> Color(pick_for=\"foo\", picker=my_picker, pick_key=None)\n    <Color blue>\n\nYou might want to use a particular picker, but enforce how the picker will\nidentify two object as the same (or not). So there's a ``pick_key`` attribute\nthat is provided and defaults as equivalent of ``hash`` method and if hash is\nnot supported by your object, it'll default to the ``str`` of your object salted\nwith the class name.\n\nThus::\n\n    >>> class MyObj(str): pass\n    >>> my_obj_color = Color(pick_for=MyObj(\"foo\"))\n    >>> my_str_color = Color(pick_for=\"foo\")\n    >>> my_obj_color == my_str_color\n    False\n\nPlease make sure your object is hashable or \"stringable\" before using the\n``RGB_color_picker`` picking mechanism or provide another color picker. Nearly\nall python object are hashable by default so this shouldn't be an issue (e.g. \ninstances of ``object`` and subclasses are hashable).\n\nNeither ``hash`` nor ``str`` are perfect solution. So feel free to use\n``pick_key`` at ``Color`` instantiation time to set your way to identify\nobjects, for instance::\n\n    >>> a = object()\n    >>> b = object()\n    >>> Color(pick_for=a, pick_key=id) == Color(pick_for=b, pick_key=id)\n    False\n\nWhen choosing a pick key, you should closely consider if you want your color\nto be consistent between runs (this is NOT the case with the last example),\nor consistent with the content of your object if it is a mutable object.\n\nDefault value of ``pick_key`` and ``picker`` ensures that the same color will\nbe attributed to same object between different run on different computer for\nmost python object.\n\n\nColor factory\n-------------\n\nAs you might have noticed, there are few attributes that you might want to see\nattached to all of your colors as ``equality`` for equality comparison support,\nor ``picker``, ``pick_key`` to configure your object color picker.\n\nYou can create a customized ``Color`` factory thanks to the ``make_color_factory``::\n\n    >>> from colour import make_color_factory, HSL_equivalence, RGB_color_picker\n\n    >>> get_color = make_color_factory(\n    ...    equality=HSL_equivalence,\n    ...    picker=RGB_color_picker,\n    ...    pick_key=str,\n    ... )\n\nAll color created thanks to ``CustomColor`` class instead of the default one\nwould get the specified attributes by default::\n\n    >>> black_red = get_color(\"red\", luminance=0)\n    >>> black_blue = get_color(\"blue\", luminance=0)\n\nOf course, these are always instances of ``Color`` class::\n\n    >>> isinstance(black_red, Color)\n    True\n\nEquality was changed from normal defaults, so::\n\n    >>> black_red == black_blue\n    False\n\nThis because the default equivalence of ``Color`` was set to\n``HSL_equivalence``.\n\n\nContributing\n============\n\nAny suggestion or issue is welcome. Push request are very welcome,\nplease check out the guidelines.\n\n\nPush Request Guidelines\n-----------------------\n\nYou can send any code. I'll look at it and will integrate it myself in\nthe code base and leave you as the author. This process can take time and\nit'll take less time if you follow the following guidelines:\n\n- check your code with PEP8 or pylint. Try to stick to 80 columns wide.\n- separate your commits per smallest concern.\n- each commit should pass the tests (to allow easy bisect)\n- each functionality/bugfix commit should contain the code, tests,\n  and doc.\n- prior minor commit with typographic or code cosmetic changes are\n  very welcome. These should be tagged in their commit summary with\n  ``!minor``.\n- the commit message should follow gitchangelog rules (check the git\n  log to get examples)\n- if the commit fixes an issue or finished the implementation of a\n  feature, please mention it in the summary.\n\nIf you have some questions about guidelines which is not answered here,\nplease check the current ``git log``, you might find previous commit that\nwould show you how to deal with your issue.\n\n\nLicense\n=======\n\nCopyright (c) 2012-2017 Valentin Lab.\n\nLicensed under the `BSD License`_.\n\n.. _BSD License: http://raw.github.com/vaab/colour/master/LICENSE\n\nChangelog\n=========\n\n\n0.1.4 (2017-04-19)\n------------------\n\nFix\n~~~\n- ``rgb2hsl`` would produce invalid hsl triplet when red, blue, green\n  component would be all very close to ``1.0``. (fixes #30) [Valentin\n  Lab]\n\n  Typically, saturation would shoot out of range 0.0..1.0. That could then\n  lead to exceptions being casts afterwards when trying to reconvert this\n  HSL triplet to RGB values.\n\n\n0.1.3 (2017-04-08)\n------------------\n\nFix\n~~~\n- Unexpected behavior with ``!=`` operator. (fixes #26) [Valentin Lab]\n- Added mention of the ``hex_l`` property. (fixes #27) [Valentin Lab]\n\n\n0.1.2 (2015-09-15)\n------------------\n\nFix\n~~~\n- Support for corner case 1-wide ``range_to`` color scale. (fixes #18)\n  [Valentin Lab]\n\n\n0.1.1 (2015-03-29)\n------------------\n\nFix\n~~~\n- Avoid casting an exception when comparing to non-``Colour`` instances.\n  (fixes #14) [Riziq Sayegh]\n\n\n0.0.6 (2014-11-18)\n------------------\n\nNew\n~~~\n- Provide all missing *2* function by combination with other existing\n  ones (fixes #13). [Valentin Lab]\n- Provide full access to any color name in HSL, RGB, HEX convenience\n  instances. [Valentin Lab]\n\n  Now you can call ``colour.HSL.cyan``, or ``colour.HEX.red`` for a direct encoding of\n  ``human`` colour labels to the 3 representations.\n\n\n0.0.5 (2013-09-16)\n------------------\n\nNew\n~~~\n- Color names are case insensitive. [Chris Priest]\n\n  The color-name structure have their names capitalized. And color names\n  that are made of only one word will be displayed lowercased.\n\nFix\n~~~\n- Now using W3C color recommandation. [Chris Priest]\n\n  Was using X11 color scheme before, which is slightly different from\n  W3C web color specifications.\n- Inconsistency in licence information (removed GPL mention). (fixes #8)\n  [Valentin Lab]\n- Removed ``gitchangelog`` from ``setup.py`` require list. (fixes #9)\n  [Valentin Lab]\n\n\n0.0.4 (2013-06-21)\n------------------\n\nNew\n~~~\n- Added ``make_color_factory`` to customize some common color\n  attributes. [Valentin Lab]\n- Pick color to identify any python object (fixes #6) [Jonathan Ballet]\n- Equality support between colors, customizable if needed. (fixes #3)\n  [Valentin Lab]\n\n\n0.0.3 (2013-06-19)\n------------------\n\nNew\n~~~\n- Colour is now compatible with python3. [Ryan Leckey]\n\n\n0.0.1 (2012-06-11)\n------------------\n- First import. [Valentin Lab]\n\nTODO\n====\n\n- ANSI 16-color and 256-color escape sequence generation\n- YUV, HSV, CMYK support\n\n\n\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "converts and manipulates various color representation (HSL, RVB, web, X11, ...)",
    "version": "0.1.5",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9904afaee027aa215976ec87a30e27be",
                "sha256": "33f6db9d564fadc16e59921a56999b79571160ce09916303d35346dddc17978c"
            },
            "downloads": -1,
            "filename": "colour-0.1.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9904afaee027aa215976ec87a30e27be",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 23772,
            "upload_time": "2017-11-19T23:20:04",
            "upload_time_iso_8601": "2017-11-19T23:20:04.560517Z",
            "url": "https://files.pythonhosted.org/packages/74/46/e81907704ab203206769dee1385dc77e1407576ff8f50a0681d0a6b541be/colour-0.1.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "5f473c29e0c867ce0241ddba8cd552d6",
                "sha256": "af20120fefd2afede8b001fbef2ea9da70ad7d49fafdb6489025dae8745c3aee"
            },
            "downloads": -1,
            "filename": "colour-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "5f473c29e0c867ce0241ddba8cd552d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24776,
            "upload_time": "2017-11-19T23:20:08",
            "upload_time_iso_8601": "2017-11-19T23:20:08.015286Z",
            "url": "https://files.pythonhosted.org/packages/a0/d4/5911a7618acddc3f594ddf144ecd8a03c29074a540f4494670ad8f153efe/colour-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2017-11-19 23:20:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "vaab",
    "github_project": "colour",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "appveyor": true,
    "lcname": "colour"
}
        
Elapsed time: 0.01418s