Color

class Color(red: int | str | Color | Color | None = None, green: int | None = None, blue: int | None = None, alpha: int | None = None)

Simple, immutable, hashable color class with flexible construction.

Examples

>>> Color()
Color(red=0, green=0, blue=0, alpha=255)
>>> Color(255, 0, 255)
Color(red=255, green=0, blue=255, alpha=255)
>>> Color(255, 0, 255, 128)
Color(red=255, green=0, blue=255, alpha=128)
>>> red = Color("red")
>>> red
Color(red=255, green=0, blue=0, alpha=255)
>>> Color(red)
Color(red=255, green=0, blue=0, alpha=255)
>>> Color(svgelements.Color("#0f0"))
Color(red=0, green=255, blue=0, alpha=255)

Methods

as_floats

Returns a float representation of the instance.

as_hex

Return a standard, hexadecimal representation of the instance.

as_rgb_hex

Return a standard, hexadecimal representation of the instance, ignoring alpha.

Attributes

Parameters:

Methods

Color.as_floats() tuple[float, float, float, float]

Returns a float representation of the instance.

Return type:

tuple[float, float, float, float]

Color.as_hex() str

Return a standard, hexadecimal representation of the instance.

Return type:

str

Color.as_rgb_hex() str

Return a standard, hexadecimal representation of the instance, ignoring alpha.

Return type:

str

Attributes

Color.red: int
Color.green: int
Color.blue: int
Color.alpha: int