CLASS v1.8.0

Color

pykraken.Color

Represents an RGBA color.

More about Color

Each channel (r, g, b, a) is an 8-bit unsigned integer.

Reference

PYTHON API

Constructor

method3 overloads
Color()
Color(r: int, g: int, b: int, a: int = 255)
Color(hex: str)

Overloaded function.

  1. Color()

Create a Color with default values (0, 0, 0, 255).

  1. 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.
  1. Color(hex: str)

Create a Color from a hex string.

Args

  • hex (str) — Hex color string (with or without '#' prefix).

a

property
a: int

Alpha (transparency) channel value.

Type: int Range: 0-255 (8-bit unsigned integer) Note: 0 = fully transparent, 255 = fully opaque

b

property
b: int

Blue channel value.

Type: int Range: 0-255 (8-bit unsigned integer)

g

property
g: int

Green channel value.

Type: int Range: 0-255 (8-bit unsigned integer)

hex

property
hex: str

Get 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

property
hsv: 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

property
r: int

Red channel value.

Type: int Range: 0-255 (8-bit unsigned integer)

copy

method
copy(self) -> Color

Create a copy of the color.

Returns

  • Color — A new Color object with the same RGBA values.

Find your next step

Start typing to search the manual.