Colors
Color
RGBA color utilities and constructors.
__init__
__init__(r: int, g: int, b: int, a: int = 255)
Initialize the color.
Parameters:
- r (int): The red value (0-255).
- g (int): The green value (0-255).
- b (int): The blue value (0-255).
- a (int): The alpha value (0-255).
from_hex
classmethod
from_hex(hex_code: str, alpha: int = 255) -> Color
Initialize the color from a hex code.
Parameters:
- hex_code (str): The hex code (#RRGGBB or #RRGGBBAA).
- alpha (int): The alpha value (used if hex code does not include alpha).
Returns:
- Color: The color instance.
Raises:
- ValueError: If the hex code is not 6 characters.
from_name
classmethod
from_name(name: str = 'aqua', alpha: int = 255) -> Color
Initialize the color from a name.
Parameters:
- name (str): The name of the color.
- alpha (int): The alpha value.
Returns:
- Color: The color instance.
Raises:
- ValueError: If the name is not found in any color list.
from_rgba
classmethod
from_rgba(rgba: tuple[int, int, int, int]) -> Color
Initialize the color from a tuple of 4 integers (0 to 255).
Parameters:
- rgba (tuple[int, int, int, int]): The RGBA values (each 0 to 255).
Returns:
- Color: The color instance.
Raises:
- ValueError: If the tuple length is not 4.
from_rgba_percent
classmethod
from_rgba_percent(
rgba: tuple[float, float, float, float],
) -> Color
Initialize the color from a tuple of 4 floats (0.0 to 1.0).
Parameters:
- rgba (tuple[float, float, float, float]): The RGBA values (each 0.0 to 1.0).
Returns:
- Color: The color instance.
Raises:
- ValueError: If the tuple length is not 4.