Colors aren't that scary!
Convert colors between rgb, hsv, and hex, perform arithmetic, blend modes, and generate random colors within boundaries
$ pip install colors.py
>>> from colors import rgb, hsv, hex, random
>>> rgb(100, 100, 100)
>>> rgb(100, 100, 100).hex
>>> str(rgb(100, 100, 100).hex) 646464
>>> hex('646464')
>>> hex('646464').rgb.red 100
>>> hex('646464').hsv
>>> list(hex('646464').hsv) [0.0, 0.0, 0.39215686274509803]
>>> hsv(0, 1, 1)
>>> hsv(0, 1, 1).rgb
>>> random()
>>> '#%s' % random().hex '#2f2336'
>>> 'style="color: rgb(%s)"' % random().rgb 'style="color: rgb(80.3414147839, 124.403236079, 71.4620739603)"'
>>> rgb(100, 100, 100) == hex('646464') True >>> hsv(0, 1, 1) == rgb(255, 0, 0) True
Note: All arithmetic operations return
rgbcolor.
>>> hex('ff9999') * hex('cccccc') >>> _.hex >>> rgb(100, 100, 100).multiply(hsv(0, 1, 1)).hex >>>
>>> hex('ff9999') + rgb(10, 10, 10) >>> hex('aaffcc').add(rgb(10, 10, 10))
>>> hex('ff9999') - rgb(10, 10, 10) >>> hex('aaffcc').subtract(rgb(10, 10, 10))
>>> hex('ff9999') / rgb(10, 10, 10) >>> hex('aaffcc').divide(rgb(10, 10, 10)) >>> rgb(100, 100, 100) / hex('00ffff') Traceback (most recent call last): File "", line 1, in File "colors.py", line 73, in divide raise ZeroDivisionError ZeroDivisionError
Note: All blend modes return
rgbcolor.
>>> hex('ff9999').screen(rgb(10, 10, 10)).hex
>>> hex('ff9999').difference(rgb(10, 10, 10)).hex
>>> hex('ff9999').overlay(rgb(10, 10, 10)).hex
>>> hex('000000').invert()
colors.pycurrent ships with three color palettes full of constants. See source for all available colors.
colors.primary
>>> import colors.primary >>> colors.primary.red
colors.rainbow
>>> import colors.rainbow >>> colors.rainbow.indigo
colors.w3c
>>> import colors.w3c >>> colors.w3c.ghostwhite
The color wheel allows you to randomly choose colors while keeping the colors relatively evenly distributed. Think generating random colors without pooling in one hue, e.g., not 50 green, and 1 red. ```python
from colors import ColorWheel wheel = ColorWheel() ```
Iterate the wheel to get the next value
ColorWheel is an iterable, but be careful if using inside any type of loop. It will iterate forever until you interject. ```python wheel.next() wheel.next() for color in wheel: ... print color.hex 00cca4 002ecc
Forever and ever and ever and ever