Color

Functions for creating and manipulating colors.

From Hex


from_hex(hex: str) → Color

Create a Color from a hex string (e.g. "#FF00FF" or "#FF00FF80").

Parameters

  • hex : The color hex code to turn into an RGBA Color object.

Returns

Color : A color object containing RGBA values represented by the provided hex string.

From HSV


from_hsv(h: float, s: float, v: float, a: float = 1.0) → Color

Create a Color from HSV(A) values.

Parameters

  • h : Hue angle [0-360].
  • s : Saturation [0-1].
  • v : Value/brightness [0-1].
  • a : Alpha [0-1]. Defaults to 1.0.

Returns

Color : A color object containing RGBA values represented by the provided HSV(A) values.

Lerp


lerp(a: Color, b: Color, t: float) → Color

Linearly interpolate between two colors.

Parameters

  • a : Start color.
  • b : End color.
  • t : Blend factor (0.0 = a, 1.0 = b).

Returns

Color : The color at the current position in interpolation.

Invert


invert(color: Color) → Color

Return the inverse of a color (flips RGB channels).

Parameters

  • color : The color to invert.

Returns

Color : The color with its RGB values inverted.

Grayscale


grayscale(color: Color) → Color

Convert a color to grayscale.

Parameters

  • color : The color to convert.

Returns

Color : The grayscale version of the color.