Color Classes¶
For a LED project color manipulation is of course the most important
part. The WS2812b needs for every pixel the RGB values, where every
component is represented as byte [0;255]. From a artistic point of
view the HSV color space is much more intuitive. Therefore this library
provides convenience classes to create, manipulate and convert classes
in RGB (RGBColor
) and HSV (HSVColor
) color space.
For more information about the HSV color space, checkout the wikipedia page.
Gamma Correction¶
The library uses the following table for gamma correction. Each channel value from
an RGB color is map to the corresponding corrected color.This table is especially
made for the WS2812b leds. To convert a byte u can use the static method
gammaCorrection()
.
gamma8_table = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 ]
Color¶
-
class
ledwall.components.
Color
(r=0, g=0, b=0)¶ Represents a color on the display. Because of the nature of the WS2812b LED, colors are represented in the RGB color space. Each component is represented as a byte value [0;255].
Color instances can be created directly or can be converted from
RGBColor
instances orHSVColor
instances.This class provides a class method for gamacorrection. The gamma correction table is especially made for the WS2812b LEDs.
-
blue
¶ Returns the blue component of this color.
Return type: int
-
floatValues
¶ Tuple of float values for the RGB channel.
-
static
fromHSVColor
(color)¶ Class method to create a new color instance from an existing HSVColor instance.
Parameters: color (HSVColor) – The HSVColor instance Return type: Color
-
static
fromHexString
(color)¶ Creates a color instance from an css color string in hexadicimal notation.
Example:
from ledwall.components import * c = Color.fromHexString('#3F234A')
Parameters: color (str) – The hex string notation of the collor. Return type: Color
-
static
fromTuple
(t)¶ Creates an instance from the first three values of the provided tuple. The tree values must be ints and within the range [0;255]. Color order is RGB.
Example:
from ledwall.components import * c = Color.fromTuple((255,12,234))
Parameters: t (tuple(int)) – A zubple with the RGB channel values. Return type: Color
-
gamma8
¶ Tuple of gamma8 corrected RGB values.
-
static
gammaCorrection
(val)¶ Maps the provided values to the corresponding gamma corrected values. See also the property
gamma8()
.from ledwall.components import * gamma8_table = [ Color.gamma_correction(c) for c in range(256) ] color = Color(244,5,54) gcolor = [ Color.gamma_correction(c) for c in color ] garr = Color.gamma_correction([245,23,16,47,3,89,167,213])
Parameters: val ((int or iterable(int))) – The value or the values to be corrected.
-
green
¶ Returns the green component of this color.
Return type: int
-
hexStr
¶ Property for hexadecimal string representation of this color with a leading #. This is an R/W property
For Example:
Color c = Color(255,0,16) print c.hexStr # This will print '#FF0010' to the console # Example for setting a color value c.hexStr = '#ffcc23'
-
hsvColor
¶ Property for getting a converted HSVColor instance or updating the RGB channels by a HSVColor instance.
-
red
¶ Returns the red component of this color.
Return type: int
-
rgbColor
¶ Converted RGBColor instance
-