Color

class Color(red=None, green=None, blue=None, alpha=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.

Attributes

red

green

blue

alpha

Methods

Color.as_floats()

Returns a float representation of the instance.

Return type

Tuple[float, float, float, float]

Color.as_hex()

Return a standard, hexadecimal representation of the instance.

Return type

str

Attributes

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