This module defines some colors and color conversion functions. It also defines a default palette of colors.
The following table shows the colors of the default palette, with their name, RGB values in 0..1 range and luminance.
>>> for k,v in palette.iteritems():
... print("%12s = %s -> %0.3f" % (k,v,luminance(v)))
black = (0.0, 0.0, 0.0) -> 0.000
red = (1.0, 0.0, 0.0) -> 0.213
green = (0.0, 1.0, 0.0) -> 0.715
blue = (0.0, 0.0, 1.0) -> 0.072
cyan = (0.0, 1.0, 1.0) -> 0.787
magenta = (1.0, 0.0, 1.0) -> 0.285
yellow = (1.0, 1.0, 0.0) -> 0.928
white = (1.0, 1.0, 1.0) -> 1.000
darkgrey = (0.5, 0.5, 0.5) -> 0.214
darkred = (0.5, 0.0, 0.0) -> 0.046
darkgreen = (0.0, 0.5, 0.0) -> 0.153
darkblue = (0.0, 0.0, 0.5) -> 0.015
darkcyan = (0.0, 0.5, 0.5) -> 0.169
darkmagenta = (0.5, 0.0, 0.5) -> 0.061
darkyellow = (0.5, 0.5, 0.0) -> 0.199
lightgrey = (0.8, 0.8, 0.8) -> 0.604
Classes defined in module colors
Functions defined in module colors
Convert a color to an OpenGL RGB color.
The output is a tuple of three RGB float values ranging from 0.0 to 1.0. The input can be any of the following:
Any other input may give unpredictable results.
Examples: >>> GLcolor(‘indianred’) (0.803921568627451, 0.3607843137254902, 0.3607843137254902) >>> print(GLcolor(‘#ff0000’)) (1.0, 0.0, 0.0) >>> GLcolor(red) (1.0, 0.0, 0.0) >>> GLcolor([200,200,255]) (0.7843137254901961, 0.7843137254901961, 1.0) >>> GLcolor([1.,1.,1.]) (1.0, 1.0, 1.0)
Return an RGB (0-255) tuple for a color
color can be anything that is accepted by GLcolor. Returns the corresponding RGB tuple.
Return an RGBA (0-255) tuple for a color and alpha value.
color can be anything that is accepted by GLcolor. Returns the corresponding RGBA tuple.
Return an RGB hex string for a color
color can be anything that is accepted by GLcolor. Returns the corresponding WEB color, which is a hexadecimal string representation of the RGB components.
Return a string designation for the color.
color can be anything that is accepted by GLcolor. In the current implementation, the returned color name is the WEBcolor (hexadecimal string).
Examples: >>> colorName(‘red’) ‘#ff0000’ >>> colorName(‘#ffddff’) ‘#ffddff’ >>> colorName([1.,0.,0.5]) ‘#ff0080’
Compute the luminance of a color.
Returns a floating point value in the range 0..1 representing the luminance of the color. The higher the value, the brighter the color appears to the human eye.
This can be for example be used to derive a good contrasting foreground color to display text on a colored background. Values lower than 0.5 contrast well with white, larger value contrast better with black.
Example:
>>> print([ "%0.2f" % luminance(c) for c in ['black','red','green','blue']])
['0.00', '0.21', '0.72', '0.07']
Return the closest color name.
Adds an alpha channel to an RGB color
Returns a grey OpenGL color of given intensity (0..1)