Giter Site home page Giter Site logo

colour's Introduction

Colour

Latest PyPI version License Compatible python versions Number of PyPI downloads Travis CI build status Appveyor CI build status 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.

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.

colour's People

Contributors

dvklopfenstein avatar edwardbetts avatar hellais avatar jdongian avatar mehcode avatar multani avatar priestc avatar sayeghr avatar vaab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colour's Issues

Implement major color representations

Nice job with this library.

The only thing I think is that it does not implement all the colour representations. Here's a check-list to motivate you to add those.

  • Web (Hex/Colour Names)
  • RGB
  • CIELAB (LAB)
  • HCL / LCH
  • HSL
  • HSV
  • XYZ
  • CYM
  • CYMK

Possibly the best part of this library is that it is independent (single-file, no dependencies). I request you to please keep it the same.

Maximum recursion depth exceeded while installing from source

Hi all,
When trying to install this package from source in ArchLinux using the pacaur AUR helper, I get the following error:

:: Retrieving package(s)...
Cloning into 'python-colour'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 4 (delta 0)
Unpacking objects: 100% (4/4), done.
:: View python-colour PKGBUILD? [Y/n] n
:: Checking python-colour integrity...
==> Making package: python-colour 0.1.2-1 (Fri Aug 18 11:20:50 CEST 2017)
==> Retrieving sources...
  -> Cloning colour git repo...
Cloning into bare repository '/home/matteo/.cache/pacaur/python-colour/colour'...
remote: Counting objects: 351, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 351 (delta 1), reused 0 (delta 0), pack-reused 348
Receiving objects: 100% (351/351), 162.40 KiB | 127.00 KiB/s, done.
Resolving deltas: 100% (207/207), done.
==> Validating source files with md5sums...
    colour ... Skipped
:: Building python-colour package(s)...
==> Making package: python-colour 0.1.2-1 (Fri Aug 18 11:20:54 CEST 2017)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> WARNING: Using existing $srcdir/ tree
==> Entering fakeroot environment...
==> Starting package()...
Missing version information: running './autogen.sh'...

Installed /home/matteo/.cache/pacaur/python-colour/src/colour/.eggs/d2to1-0.2.12.post1-py3.6.egg
error in setup command: Error parsing /home/matteo/.cache/pacaur/python-colour/src/colour/setup.cfg: RecursionError: maximum recursion depth exceeded
==> ERROR: A failure occurred in package().
    Aborting...
:: failed to build python-colour package(s)

Any idea on how to solve this? I'm not a Python expert and this seems to be a package related issue, instead of a distribution issue.

update the rgb_to_color

RGB_TO_COLOR_NAMES = {
(240, 248, 255): ['aliceblue'],
(250, 235, 215): ['antiquewhite'],
(0, 255, 255): ['aqua'],
(127, 255, 212): ['aquamarine'],
(240, 255, 255): ['azure'],
(245, 245, 220): ['beige'],
(255, 228, 196): ['bisque'],
(0, 0, 0): ['black'],
(255, 235, 205): ['blanchedalmond'],
(0, 0, 255): ['blue'],
(138, 43, 226): ['blueviolet'],
(165, 42, 42): ['brown'],
(222, 184, 135): ['burlywood'],
(95, 158, 160): ['cadetblue'],
(127, 255, 0): ['chartreuse'],
(210, 105, 30): ['chocolate'],
(255, 127, 80): ['coral'],
(100, 149, 237): ['cornflowerblue'],
(255, 248, 220): ['cornsilk'],
(220, 20, 60): ['crimson'],
(0, 255, 255): ['cyan'],
(0, 0, 139): ['darkblue'],
(0, 139, 139): ['darkcyan'],
(184, 134, 11): ['darkgoldenrod'],
(169, 169, 169): ['darkgray'],
(0, 100, 0): ['darkgreen'],
(189, 183, 107): ['darkkhaki'],
(139, 0, 139): ['darkmagenta'],
(85, 107, 47): ['darkolivegreen'],
(255, 140, 0): ['darkorange'],
(153, 50, 204): ['darkorchid'],
(139, 0, 0): ['darkred'],
(233, 150, 122): ['darksalmon'],
(143, 188, 143): ['darkseagreen'],
(72, 61, 139): ['darkslateblue'],
(47, 79, 79): ['darkslategray'],
(0, 206, 209): ['darkturquoise'],
(148, 0, 211): ['darkviolet'],
(255, 20, 147): ['deeppink'],
(0, 191, 255): ['deepskyblue'],
(105, 105, 105): ['dimgray'],
(30, 144, 255): ['dodgerblue'],
(178, 34, 34): ['firebrick'],
(255, 250, 240): ['floralwhite'],
(34, 139, 34): ['forestgreen'],
(255, 0, 255): ['fuchsia'],
(220, 220, 220): ['gainsboro'],
(248, 248, 255): ['ghostwhite'],
(255, 215, 0): ['gold'],
(218, 165, 32): ['goldenrod'],
(128, 128, 128): ['gray'],
(0, 128, 0): ['green'],
(173, 255, 47): ['greenyellow'],
(240, 255, 240): ['honeydew'],
(255, 105, 180): ['hotpink'],
(205, 92, 92): ['indianred'],
(75, 0, 130): ['indigo'],
(255, 255, 240): ['ivory'],
(240, 230, 140): ['khaki'],
(230, 230, 250): ['lavender'],
(255, 240, 245): ['lavenderblush'],
(124, 252, 0): ['lawngreen'],
(255, 250, 205): ['lemonchiffon'],
(173, 216, 230): ['lightblue'],
(240, 128, 128): ['lightcoral'],
(224, 255, 255): ['lightcyan'],
(250, 250, 210): ['lightgoldenrodyellow'],
(144, 238, 144): ['lightgreen'],
(211, 211, 211): ['lightgray'],
(255, 182, 193): ['lightpink'],
(255, 160, 122): ['lightsalmon'],
(32, 178, 170): ['lightseagreen'],
(135, 206, 250): ['lightskyblue'],
(119, 136, 153): ['lightslategray'],
(176, 196, 222): ['lightsteelblue'],
(255, 255, 224): ['lightyellow'],
(0, 255, 0): ['lime'],
(50, 205, 50): ['limegreen'],
(250, 240, 230): ['linen'],
(255, 0, 255): ['magenta'],
(128, 0, 0): ['maroon'],
(102, 205, 170): ['mediumaquamarine'],
(0, 0, 205): ['mediumblue'],
(186, 85, 211): ['mediumorchid'],
(147, 112, 219): ['mediumpurple'],
(60, 179, 113): ['mediumseagreen'],
(123, 104, 238): ['mediumslateblue'],
(0, 250, 154): ['mediumspringgreen'],
(72, 209, 204): ['mediumturquoise'],
(199, 21, 133): ['mediumvioletred'],
(25, 25, 112): ['midnightblue'],
(245, 255, 250): ['mintcream'],
(255, 228, 225): ['mistyrose'],
(255, 228, 181): ['moccasin'],
(255, 222, 173): ['navajowhite'],
(0, 0, 128): ['navy'],
(253, 245, 230): ['oldlace'],
(128, 128, 0): ['olive'],
(107, 142, 35): ['olivedrab'],
(255, 165, 0): ['orange'],
(255, 69, 0): ['orangered'],
(218, 112, 214): ['orchid'],
(238, 232, 170): ['palegoldenrod'],
(152, 251, 152): ['palegreen'],
(175, 238, 238): ['paleturquoise'],
(219, 112, 147): ['palevioletred'],
(255, 239, 213): ['papayawhip'],
(255, 218, 185): ['peachpuff'],
(205, 133, 63): ['peru'],
(255, 192, 203): ['pink'],
(221, 160, 221): ['plum'],
(176, 224, 230): ['powderblue'],
(128, 0, 128): ['purple'],
(255, 0, 0): ['red'],
(188, 143, 143): ['rosybrown'],
(65, 105, 225): ['royalblue'],
(139, 69, 19): ['saddlebrown'],
(250, 128, 114): ['salmon'],
(244, 164, 96): ['sandybrown'],
(46, 139, 87): ['seagreen'],
(255, 245, 238): ['seashell'],
(160, 82, 45): ['sienna'],
(192, 192, 192): ['silver'],
(135, 206, 235): ['skyblue'],
(106, 90, 205): ['slateblue'],
(112, 128, 144): ['slategray'],
(255, 250, 250): ['snow'],
(0, 255, 127): ['springgreen'],
(70, 130, 180): ['steelblue'],
(210, 180, 140): ['tan'],
(0, 128, 128): ['teal'],
(216, 191, 216): ['thistle'],
(255, 99, 71): ['tomato'],
(64, 224, 208): ['turquoise'],
(238, 130, 238): ['violet'],
(245, 222, 179): ['wheat'],
(255, 255, 255): ['white'],
(245, 245, 245): ['whitesmoke'],
(255, 255, 0): ['yellow'],
(154, 205, 50): ['yellowgreen']
}

RGBA support

CSS spec defined an RGBA color specification: https://www.w3.org/wiki/CSS3/Color/RGBA

However, passing a value like 'rgba(0, 0, 0, 1)' results an the error:

ValueError: 'rgba(0,0,0,1)' is not a recognized color.

This makes storing values that are intended for use in stylesheets impossible without doing unnecessary conversion.

HSV support

Is HSV going to be supported? The readme says it is supported, but I found only HSL implemented.

Thank you.

add option for shortest path from purple to blue

Hello, when i use

oldcolor = Color('#800080')
newcolor = Color('#000080')
oldcolor.range_to(newcolor, 100)

the list goes through the whole rainbow (red, yellow, etc).
An option for a range with a shortest path, kind of a CMYK way, transitioning trough mauve or lilac to blue would be nice.

Using named tuples

Currently, All attributes and methods of Color return tuples or strings. It should be relatively simple to return namedtuples instead of simple tuples.

Why?
Namedtuple makes your tuples _self-document. You can easily understand what is going on by having a quick glance at your code._1

Lightness vs luminance?

I might be totally off base here, but i think you're conflating lightness and luminance?

HSL is hue, saturation, lightness

luminance is sqrt( 0.299R^2 + 0.587G^2 + 0.114*B^2 )

feature request: pseudo-continuous color ranges for numeric data

Is there a one-liner that I can use to get the color of a numeric value? For example, I want to make a color range from blue to red using 256 levels, where blue somehow maps to 0.0 and red maps to 1.0. From the markdown file I've come up with the following workflow.

from colour import Color
import numpy as np

# make the base colors
red = Color("red")
blue = Color("blue")

# define the color range
levels = 256
r_to_b = list(red.range_to(blue, levels))

def map(x, color_range, m=0.0, M=1.0):
    """ This map converts a numeric value to Color object in a list of Color objects """
    n = len(color_range)
    numeric_range = np.linspace(m,M,n)
    nearest_idx = np.abs(x - numeric_range).argmin()
    return color_range[nearest_idx]

# retrieve the color of float x
x = 0.2425
color_x = map(x, r_to_b)

Is this functionality already present in colour, or do you see a better implementation?

the following tuple (0.9999999999999999, 0.9999999999999999, 1.0) put satuation over 1, which trigger a crash on print.

r, g, b = (0.9999999999999999, 0.9999999999999999, 1.0)
c = Color(red=r, green=g, blue=b)
print or log c

traceback :

  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1084, in __str__
    return "%s" % self.web
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 983, in __getattr__
    return getattr(self, 'get_' + label)()
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1029, in get_web
    return hex2web(self.hex)
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 983, in __getattr__
    return getattr(self, 'get_' + label)()
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1002, in get_hex
    return rgb2hex(self.rgb)
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 983, in __getattr__
    return getattr(self, 'get_' + label)()
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1008, in get_rgb
    return hsl2rgb(self.hsl)
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 346, in hsl2rgb
    raise ValueError("Saturation must be between 0 and 1.")

Source install on Slackware autogen.sh failure

Hello, I am trying to install colour in Slackware 15 Beta 1 and I am getting this error when I run ./autogen.sh.

autogen.sh: error: Didn't find a git repository (or no tags found). ``./autogen.sh`` uses git to create changelog and version information.

As I understand it autogen.sh should create a Changelog.rst file needed by setup.py. However I need to get past the above error. Any help with this is appreciated.

Thank You.

can not import Colour from colour (unknown location)

I can not import the most basic class and that is Color

from colour import Color
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'Color' from 'colour' (unknown location)

this is in python3, and I am trying to run manim python code. How can I fix this?

License

In setup it is stated that this package is GPL and BSD licensed. Which one is it? Would it be possible to make this wonderful package BSD licensed?

ImportError: cannot import name 'addstr' from partially initialized module 'culour' (most likely due to a circular import)

% python
Python 3.8.1 (default, Jan 26 2020, 17:08:51) 
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import culour
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/venv/lib/python3.8/site-packages/culour/__init__.py", line 1, in <module>
    from culour import addstr
ImportError: cannot import name 'addstr' from partially initialized module 'culour' (most likely due to a circular import)

Normalized Hex

I just wanted to say thank you for working on things like this. Your color range list function was a lifesaver for me.
I did have a problem once in a while with matplotlib where it wouldn't recognize a non-normalized web hex format. For example, a value in the middle of a range landed on #393. Matplotlib wouldn't take this value as it apparently needed the normalized #339933. I used the webcolors package to normalize the output of my color range lists from colour to avoid the random problem of landing on a color value that didn't need all 6 digits to represent it. Before webcolors I tried formatting the color value using "%s"% and .hex but it remained a 3 digit color value that matplotlib wouldn't take. The piece of code they use to normalize is this:
if len(hex_digits) == 3:
hex_digits = u''.join(2 * s for s in hex_digits)

If I'm going about this reporting wrong maybe you can let me know what I should be doing differently. I'm new to open source projects like this. Thanks.

Sam

import error with 0.1.0

Hi there,

Linux 3.13.0-29-generic #53-Ubuntu SMP Wed Jun 4 21:00:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Python 2.7.9

pip install colour
Collecting colour
Using cached colour-0.1.0.tar.gz
Installed /tmp/pip-build-jSjeRq/colour/.eggs/d2to1-0.2.11-py2.7.egg
[d2to1] running patched manifest_maker command with extra_files support
Installing collected packages: colour
Running setup.py install for colour
[d2to1] running patched manifest_maker command with extra_files support
Successfully installed colour-0.1.0

from colour import Color
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named colour

Inverted Color

It would be cool to have an .inverted property which would return an inverted Color object.

Explanation of how to use this package in combination with matplotlib?

Hi, I am trying to create a plot in which each line is picked from a colormap, like in this code:

import matplotlib.pylab as plt
import numpy as np
x = np.linspace(0,10,100)
n_lines = 3
cl = plt.cm.cool(np.linspace(0, 1, n_lines))
for i in range(3):
    plt.plot(x,x**(i+1),color=cl[i])
plt.show()

How can I use colour package in order to create a custom gradient and use it with matplotlib? I tried to create a gradient from brown to green in this way:

from colour import Color
brown = Color("brown")
cl = list(brown.range_to(Color("green"),3))

But it gave me error when plugging cl to the code I've given above..

Package is not git-install-able

Because of the following reasons, this package is not install-able from git:

  • %%version%% is in setup.py
  • CHANGELOG.rst does not exist in the repository and setup.py depends on it.

Equality operator support

It would be very nice if Color objects had equality operator support. Defining __eq__ and __ne__ methods in Color class would suffice:

def __eq__(self, other):
    return self.hex == other.hex

def __ne__(self, other):
    return self.hex != other.hex

This would allow the following syntax to evaluate as True:

Color('white') == Color('white')

lightness based color range when using black or white

Thanks for this library, it's very cool and useful. Maybe you could add another kind of range in order to make gradients, e.g. now the color range from blue to white is "passing" through other colors, like green, while it would be nice to have also the opportunity to make a gradient from blue to white which is just making the blue paler and paler until white, so basically it would be a lightness based range.

Install problem

It pip install fails, as it can't find the CHANGELOG.rst file

ZeroDivisionError: float division by zero

Throws Traceback error, than only one color requested
list(Color("black").range_to(Color('white'),1))

ZeroDivisionError: float division by zero

Expected list with one element:
[<Color black>,]

No web2rgb

At the moment I have to wrap it like this

c = colour.hex2rgb(colour.web2hex(args))

Debian packaging in progress

Hi!

This is a friendly notice to let you know that Debian is working on packaging your software for Debian. You can follow the progress of that work in bug #867800 in the Debian Bug Tracking System (BTS).

The source code for the Debian package is in this git repository. It will be uploaded into Debian shortly, at which point it will end up in the NEW queue for legal review. Once the NEW process is completed, it takes about 10 days for the package to trickle down into "testing", which will become the next Debian release. This means your software will eventually be shipped in a "long term support" release, which last from three to five years, according to the current statistics.

If you are interested in maintaining the package yourself upstream, that is definitely possible. You can either upload the package yourself if you are a Debian member or I can act as a sponsor when a new release is published.

This is just a notification, but can also act as a coordination point for upstream packaging if you wish to followup on this. otherwise, feel free to close this issue whenever you like.

Remove gitchangelog from dependencies

Gitchangelog is only needed for the developers of this package. Regular user who only use this package as a library don't need it as a dependency.

Building from source fails

Building 0.1.4 from source fails:

Missing version information: running './autogen.sh'...
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 158, in save_modules
    yield saved
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 199, in setup_context
    yield
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 254, in run_setup
    _execfile(setup_script, ns)
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 49, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-gi3u_ihf/d2to1-0.2.12.post1/setup.py", line 17, in <module>
    from setuptools import setup
  File "/tmp/easy_install-gi3u_ihf/d2to1-0.2.12.post1/d2to1/util.py", line 204, in cfg_to_args
  File "/tmp/easy_install-gi3u_ihf/d2to1-0.2.12.post1/d2to1/util.py", line 439, in wrap_commands
  File "/usr/lib/python3.6/site-packages/setuptools/dist.py", line 589, in get_command_list
    cmdclass = ep.resolve()
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2322, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'tasks'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 64, in <module>
    d2to1=True
  File "/usr/lib/python3.6/distutils/core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/lib/python3.6/site-packages/setuptools/dist.py", line 325, in __init__
    self.fetch_build_eggs(attrs['setup_requires'])
  File "/usr/lib/python3.6/site-packages/setuptools/dist.py", line 446, in fetch_build_eggs
    replace_conflicting=True,
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 855, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1127, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1139, in obtain
    return installer(requirement)
  File "/usr/lib/python3.6/site-packages/setuptools/dist.py", line 518, in fetch_build_egg
    return cmd.easy_install(req)
  File "/usr/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 672, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 698, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 879, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 1118, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 1104, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 257, in run_setup
    raise
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 199, in setup_context
    yield
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 170, in save_modules
    saved_exc.resume()
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 145, in resume
    six.reraise(type, exc, self._tb)
  File "/usr/lib/python3.6/site-packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 158, in save_modules
    yield saved
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 199, in setup_context
    yield
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 254, in run_setup
    _execfile(setup_script, ns)
  File "/usr/lib/python3.6/site-packages/setuptools/sandbox.py", line 49, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-gi3u_ihf/d2to1-0.2.12.post1/setup.py", line 17, in <module>
    from setuptools import setup
  File "/tmp/easy_install-gi3u_ihf/d2to1-0.2.12.post1/d2to1/util.py", line 204, in cfg_to_args
  File "/tmp/easy_install-gi3u_ihf/d2to1-0.2.12.post1/d2to1/util.py", line 439, in wrap_commands
  File "/usr/lib/python3.6/site-packages/setuptools/dist.py", line 589, in get_command_list
    cmdclass = ep.resolve()
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2322, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'tasks'

Using CSS rgb notation with Color rgb argument

Hi,

I searched in code, doc and issues but i didn't find a clear way to use CSS rgb values since Color rgb argument required float values.

Like for red color i have this CSS rule:
rgb(255, 0, 0)

I attempted to be able to do:

Color(rgb=(255, 0, 0))

Did i missed some helper or easy math to perform this ?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.