Color Classes
Module containing color classes that allow for easy conversion between color spaces.
This module contains different classes that represent a few of the most common color spaces.
Although these classes may be used individually, they were originally designed to be used within a ColorDict object.
- class colordict.color.sRGBColor(r, g, b, a=None, norm=255, include_a=False, round_to=- 1)
Bases:
colordict.color.ColorTupleBase
Represents a color in the RGB color space.
- Parameters
r (float) – Red component of the color.
g (float) – Green component of the color.
b (float) – Blue component of the color.
a (float) – Opacity component of the color. Defaults to
None
, which means it will be the same as thenorm
parameter.norm – What the
r
,g
,b
, anda
components are normalized to (aka their highest possible value). Some common values for this parameter would be 255 or 1.include_a – Whether to include the opacity parameter
a
in the contructed tuple. Setting it toTrue
may result in an object such assRGBColor(255, 255, 0, 255)
instead ofsRGBColor(255, 255, 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.
- class colordict.color.HSLColor(h, s, l, a=None, h_norm=360, sla_norm=1, include_a=False, round_to=- 1)
Bases:
colordict.color.ColorTupleBase
Represents a color in the HSL color space.
- Parameters
h (float) – HUE component of the color.
s (float) – Saturation component of the color.
l (float) – Lightness component of the color.
a (float) – Opacity component of the color. Defaults to
None
, which means it will be the same as thesla_norm
parameter.h_norm – What the
h
component is normalized to (aka its highest possible value). Some common values for this parameter would be 360 or 1.sla_norm – What the
s
,l
anda
components are normalized to (aka their highest possible value). Some common values for this parameter would be 1 or 100.include_a – Whether to include the opacity parameter
a
in the contructed tuple. Setting it toTrue
may result in an object such asHSLColor(360, 1, 0, 1)
instead ofHSLColor(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
. The default, -1, means that the components won’t be rounded at all.
- class colordict.color.HSVColor(h, s, v, a=None, h_norm=360, sva_norm=1, include_a=False, round_to=- 1)
Bases:
colordict.color.ColorTupleBase
Represents a color in the HSV color space.
- Parameters
h (float) – HUE component of the color.
s (float) – Saturation component of the color.
v (float) – Value component of the color.
a (float) – Opacity component of the color. Defaults to
None
, which means it will be the same as thesva_norm
parameter.h_norm – What the
h
component is normalized to (aka its highest possible value). Some common values for this parameter would be 360 or 1.sva_norm – What the
s
,v
anda
components are normalized to (aka their highest possible value). Some common values for this parameter would be 1 or 100.include_a – Whether to include the opacity parameter
a
in the contructed tuple. Setting it toTrue
may result in an object such asHSVColor(360, 1, 0, 1)
instead ofHSVColor(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
. The default, -1, means that the components won’t be rounded at all.
- class colordict.color.CMYKColor(c, m, y, k, a=None, norm=1, include_a=False, round_to=- 1)
Bases:
colordict.color.ColorTupleBase
Represents a color in the CMYK color space.
- Parameters
c (float) – Cyan component of the color.
m (float) – Magenta component of the color.
y (float) – Yellow component of the color.
k (float) – Key (black) component of the color.
a (float) – Opacity component of the color. Defaults to
None
, which means it will be the same as thenorm
parameter.norm – What the
c
,m
,y
,k
, anda
components are normalized to (aka their highest possible value). Some common values for this parameter would be 1 or 100.include_a – Whether to include the opacity parameter
a
in the contructed tuple. Setting it toTrue
may result in an object such asCMYKColor(1, 1, 0, 1)
instead ofCMYKColor(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.
- class colordict.color.CMYColor(c, m, y, a=None, norm=1, include_a=False, round_to=- 1)
Bases:
colordict.color.ColorTupleBase
Represents a color in the CMY color space.
- Parameters
c (float) – Cyan component of the color.
m (float) – Magenta component of the color.
y (float) – Yellow component of the color.
a (float) – Opacity component of the color. Defaults to
None
, which means it will be the same as thenorm
parameter.norm – What the
c
,m
,y
anda
components are normalized to (aka their highest possible value). Some common values for this parameter would be 1 or 100.include_a – Whether to include the opacity parameter
a
in the contructed tuple. Setting it toTrue
may result in an object such asCMYColor(1, 1, 0, 1)
instead ofCMYColor(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.
- class colordict.color.HexColor(hex_str, include_a=False)
Bases:
colordict.color.ColorBase
,str
Represents a color in the RGB color space as a hexadecimal string.
Is mostly used for representing colors in web applications.
- Parameters
hex_str (str) – Hexadecimal string from which the
HexColor
instance will be built. May or may not include a “#” character in its beggining.include_a – Whether to include the opacity parameter
a
in the contructed tuple. Setting it toTrue
may result in an object such asHexColor('#ffffff00')
instead ofHexColor('#ffff00')
, for exemple.
- class colordict.color.ColorBase(rgba, **kwargs)
Bases:
object
Base class from which all color classes inherit.
Note
This class is abstract and should not be instanciated.
- hex(**kwargs)
Converts the current color to a hexadecimal representation.
- Parameters
**kwargs – Keyword arguments wrapped in this function will be passed on to the
HexColor
constructor.
- rgb(**kwargs)
Converts the current color to an sRGB representation.
- Parameters
**kwargs – Keyword arguments wrapped in this function will be passed on to the
sRGBColor
constructor.
- hsl(**kwargs)
Converts the current color to an HSL representation.
- Parameters
**kwargs – Keyword arguments wrapped in this function will be passed on to the
HSLColor
constructor.
- hsv(**kwargs)
Converts the current color to an HSV representation.
- Parameters
**kwargs – Keyword arguments wrapped in this function will be passed on to the
HSVColor
constructor.
- cmyk(**kwargs)
Converts the current color to a CMYK representation.
- Parameters
**kwargs – Keyword arguments wrapped in this function will be passed on to the
CMYKColor
constructor.
- cmy(**kwargs)
Converts the current color to a CMY representation.
- Parameters
**kwargs – Keyword arguments wrapped in this function will be passed on to the
CMYColor
constructor.
- class colordict.color.ColorTupleBase(iterable, rgba, include_a=False, round_to=- 1)
Bases:
colordict.color.ColorBase
,tuple
Base class from which all color classes that are represented by tuples inherit.
Note
This class is abstract and should not be instanciated.