color
Module#
Classes:
A color. |
- class term_image.color.Color(r, g, b, a=255)[source]#
Bases:
_DummyColor
A color.
- Parameters:
- Raises:
ValueError – The value of a channel is not within the valid range.
Note
The valid value range for all channels is 0 to 255, both inclusive.
Tip
This class is a
NamedTuple
of four fields.Warning
In the case of multiple inheritance i.e if subclassing this class along with other classes, this class should appear last (i.e to the far right) in the base class list.
Attributes:
Instance Properties:
Converts the color to its RGBA hexadecimal representation.
Extracts the R, G and B channels of the color.
Converts the color to its RGB hexadecimal representation.
Class Methods:
Creates a new instance from a hexadecimal color string.
- property hex: str#
Converts the color to its RGBA hexadecimal representation.
- Returns:
The RGBA hex color string, starting with the
#
character i.e#rrggbbaa
.Each channel is represented by two lowercase hex digits ranging from
00
toff
.
- property rgb: tuple[int, int, int]#
Extracts the R, G and B channels of the color.
- Returns:
A 3-tuple containing the red, green and blue channel values.
- property rgb_hex: str#
Converts the color to its RGB hexadecimal representation.
- Returns:
The RGB hex color string, starting with the
#
character i.e#rrggbb
.Each channel is represented by two lowercase hex digits ranging from
00
toff
.
- classmethod from_hex(color)[source]#
Creates a new instance from a hexadecimal color string.
- Parameters:
color (str) – A case-insensitive RGB or RGBA hex color string, optionally starting with the
#
(pound) character i.e[#]rrggbb[aa]
.- Returns:
A new instance representing the given hex color string.
- Raises:
ValueError – Invalid hex color string.
- Return type:
Note
For an RGB hex color string, the value of A (the alpha channel) is taken to be 255.