This module contains different classes that represent a few of the most common color spaces [1].
Colors can be compared, converted to and passed as arguments to different classes.
Color arithmetic makes it easy to change the properties of a color.
The operations are performed element-wise in the format of the color used as the right operand,
allowing specific color components to be changed in the color on the left of the operator.
If the right operand is not a color, but rather a tuple, than the left color is not converted
prior to the operation being performed.
Add some CIE lightness to the color black (right operand is CIELab, meaning that the Hex color will be converted
to CIELab before adding 50 to its lighness value and then converted back to Hex):
>>> Hex("#000000")+CIELab(50,0,0)Hex('#777777')
Make a red 50% less saturated by multiplying its saturation component by 0.5 (here no conversion is performed
because the right operand is a tuple rather than a color class):
a (float) – Opacity component of the color. Defaults to None, which means it will be the same
as the max_rgba parameter.
max_rgb – What is the maximum value for the r, g and b components. Some common
values for this parameter would be 255 or 1.
max_a – What is the maximum value for the a component. Some common
values for this parameter would be 100 or 1.
include_a – Whether to include the opacity parameter a in the constructed tuple.
Setting it to True may result in an object such as RGB(255,255,0,255) instead of RGB(255,255,0), for example.
round_to – Rounds the value of each color component to this many decimal places. Setting
this parameter to 0 ensures that the components will be of type int. -1
means that the components won’t be rounded at all.
linear – Whether the values are linear RGB or sRGB. It is strongly advised not to keep values as
linear RGB, but it can be useful for quick conversions.
a (float) – Opacity component of the color. Defaults to None, which means it will be the same
as the max_sva parameter.
max_h (float) – What is the maximum value for the h component. Some common values for this
parameter would be 360 or 1.
max_sva – What is the maximum value for the s, v and a components. Some common values
for this parameter would be 1 or 100.
include_a – Whether to include the opacity parameter a in the constructed tuple.
Setting it to True may result in an object such as HSV(360,1,0,1) instead of HSV(360,1,0), for exemple.
round_to – Rounds the value of each color component to this many decimal places. Setting
this parameter to 0 ensures that the components will be of type int. -1
means that the components won’t be rounded at all.
a (float) – Opacity component of the color. Defaults to None, which means it will be the same
as the max_sla parameter.
max_h (float) – What is the maximum value for the h component. Some common values for this
parameter would be 360 or 1.
max_sla – What is the maximum value for the s, l and a components. Some common values
for this parameter would be 1 or 100.
include_a – Whether to include the opacity parameter a in the constructed tuple.
Setting it to True may result in an object such as HSL(360,1,0,1) instead of HSL(360,1,0), for exemple.
round_to – Rounds the value of each color component to this many decimal places. Setting
this parameter to 0 ensures that the components will be of type int. -1
means that the components won’t be rounded at all.
a (float) – Opacity component of the color. Defaults to None, which means it will be the same
as the max parameter.
max_cmya – What is the maximum value for the c, m, y and a components. Some common
values for this parameter would be 1 or 100.
include_a – Whether to include the opacity parameter a in the constructed tuple.
Setting it to True may result in an object such as CMY(1,1,0,1) instead of CMY(1,1,0), for exemple.
round_to – Rounds the value of each color component to this many decimal places. Setting
this parameter to 0 ensures that the components will be of type int. The default,
-1, means that the components won’t be rounded at all.
classcolorir.color_class.CMYK(c, m, y, k, a=None, max_cmyka=1, include_a=False, round_to=-1)
a (float) – Opacity component of the color. Defaults to None, which means it will be the same
as the max parameter.
max_cmyka – What is the maximum value for the c, m, y, k and a components. Some
common values for this parameter would be 1 or 100.
include_a – Whether to include the opacity parameter a in the constructed tuple.
Setting it to True may result in an object such as CMYK(1,1,0,1) instead of CMYK(1,1,0), for exemple.
round_to – Rounds the value of each color component to this many decimal places. Setting
this parameter to 0 ensures that the components will be of type int. The default,
-1, means that the components won’t be rounded at all.
classcolorir.color_class.CIELuv(l, u, v, a=None, max_a=1, include_a=False, round_to=-1)
Represents a color in the RGB color space [7] as a hexadecimal string.
Is mostly used for representing colors in web applications [8].
References
Parameters:
hex_str (str) – Hexadecimal string from which the Hex instance will be built.
The format can be a string of 6 digits, 8 digits (with an alpha specifier in the beginning or the end),
or 3 digits, optionally including a ‘#’ character.
uppercase – Whether the color will be represented in uppercase or lowercase.
include_a – Whether to include the opacity parameter a in the constructed string.
Setting it to True may result in an object such as Hex('#ffffff00')
instead of Hex('#ffff00'), for exemple.
tail_a – Whether the alpha component is present in the tail or head of the hex string. Used
only if hex_str includes an alpha component or include_a is True.