Kraken Logo

Kraken Engine

DocumentationGuidesShowcaseCommunity
Ctrl
K
Navigating the Docs
Building Docs
Overview
Camera
Color
Draw
Ease
Event
Fx
Gamepad
Input
Log
Math
Mixer
Mouse
Physics
Pixel Array
Renderer
Shaders
Time
Transform
Ui
Viewport
Window

Built bydurkisneer1.Kraken Engine is open source and available onGitHub.

  1. Docs
  2. Functions
  3. Color

Color

Color utility functions and predefined color constants.


From Hex

from_hex(hex: str) → Colorfrom_hex(hex: str) → Color

Create a Color from a hex string.

Supports multiple hex formats:

  • "#RRGGBB" - 6-digit hex with full opacity
  • "#RRGGBBAA" - 8-digit hex with alpha
  • "#RGB" - 3-digit hex (each digit duplicated)
  • "#RGBA" - 4-digit hex with alpha (each digit duplicated)

Args

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

Returns

Color : New Color object from the hex string.

Examples : from_hex("#FF00FF") # Magenta, full opacity from_hex("#FF00FF80") # Magenta, 50% opacity from_hex("#F0F") # Same as "#FF00FF" from_hex("RGB") # Without '#' prefix

From Hsv

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

Create a Color from HSV(A) values.

Args

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

Lerp

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

Linearly interpolate between two colors.

Performs component-wise linear interpolation between start and end colors. All RGBA channels are interpolated independently.

Args

  • a : Start color (when t=0.0).
  • b : End color (when t=1.0).
  • t : Blend factor. Values outside [0,1] will extrapolate.

Returns

Color : New interpolated color.

Examples : lerp(Color.RED, Color.BLUE, 0.5) # Purple (halfway between red and blue) lerp(Color.BLACK, Color.WHITE, 0.25) # Dark gray

Invert

invert(color: Color) → Colorinvert(color: Color) → Color

Return the inverse of a color by flipping RGB channels.

The alpha channel is preserved unchanged.

Args

  • color : The color to invert.

Returns

Color : New Color with inverted RGB values (255 - original value).

Example : invert(Color(255, 0, 128, 200)) # Returns Color(0, 255, 127, 200)

Grayscale

grayscale(color: Color) → Colorgrayscale(color: Color) → Color

Convert a color to grayscale.

Args

  • color : The color to convert.

Returns

Color : New Color object representing the grayscale version.

Example : grayscale(Color(255, 0, 0)) # Returns Color(76, 76, 76, 255)

PreviousCamera
NextDraw

On this page

From HexFrom HsvLerpInvertGrayscale