Color
pykraken.Color Represents an RGBA color.
More about Color
Each channel (r, g, b, a) is an 8-bit unsigned integer.
At a glance
8 membersReference
PYTHON APIOverloaded function.
Color()
Create a Color with default values (0, 0, 0, 255).
Color(r: int, g: int, b: int, a: int = 255)
Create a Color from RGBA components.
Args
- r (
int) — Red value [0-255]. - g (
int) — Green value [0-255]. - b (
int) — Blue value [0-255]. - a (
int, optional) — Alpha value [0-255]. Defaults to 255.
Color(hex: str)
Create a Color from a hex string.
Args
- hex (
str) — Hex color string (with or without '#' prefix).
a
propertya: intAlpha (transparency) channel value.
Type: int Range: 0-255 (8-bit unsigned integer) Note: 0 = fully transparent, 255 = fully opaque
b
propertyb: intBlue channel value.
Type: int Range: 0-255 (8-bit unsigned integer)
g
propertyg: intGreen channel value.
Type: int Range: 0-255 (8-bit unsigned integer)
hex
propertyhex: strGet or set the color as a hex string.
When getting, returns an 8-digit hex string in the format "#RRGGBBAA". When setting, accepts various hex formats (see from_hex for details).
Example
color.hex = "#FF00FF" # Set to magenta print(color.hex) # Returns "#FF00FFFF"
hsv
propertyhsv: tuple[float, float, float, float]Get or set the color as an HSV tuple.
When getting, returns a tuple of (hue, saturation, value, alpha). When setting, accepts a tuple of 3 or 4 values.
Values: hue (float): Hue angle in degrees (0-360) saturation (float): Saturation level (0-1) value (float): Brightness/value level (0-1) alpha (float): Alpha transparency (0-1), optional
Example
color.hsv = (120, 1.0, 1.0) # Pure green color.hsv = (240, 0.5, 0.8, 0.9) # Light blue with transparency h, s, v, a = color.hsv # Get HSV values
r
propertyr: intRed channel value.
Type: int Range: 0-255 (8-bit unsigned integer)
copy
methodcopy(self) -> ColorCreate a copy of the color.
Returns
- Color — A new Color object with the same RGBA values.