Packed 32-bit color value with convenience accessors for RGB, HSV, and HSL channels.
Color stores channels in 0xAARRGGBB order and exposes normalized floating-point
component accessors in the 0.0..1.0 range unless noted otherwise.
It is designed to be pleasant to use in gameplay, rendering, UI, and animation
code. You can treat it as:
- a packed integer color
- a set of normalized component properties
- a small conversion hub between RGB, HSV, HSL, vectors, strings, and kha.Color
Typical usage:
var c = Color.fromString("#ff8844");
c.a = 0.5;
c.h += 0.1;
This abstract can be converted from and to Int, String, kha.Color, Vec3,
and Vec4.
See also:
Static variables
Static methods
staticinlinefromString(value:String):Color
Parses a color from a name or hexadecimal string.
Supported names include black, white, red, blue, green, magenta,
yellow, cyan, purple, pink, orange, and transparent.
Supported hexadecimal formats are #rgb, #rrggbb, and #aarrggbb.
Parameters:
value | Color name or hexadecimal literal. |
|---|
Returns:
The parsed color.
Throws:
String | If the string cannot be parsed as a color. |
|---|
staticinlinefromVec3(value:Vec3):Color
Creates a color from a normalized RGB vector.
Parameters:
value | RGB channels in |
|---|
Returns:
The resulting color.
staticinlinefromVec4(value:Vec4):Color
Creates a color from a normalized RGBA vector.
Parameters:
value | RGBA channels in |
|---|
Returns:
The resulting color.
staticinlinehsl(h:Float, s:Float, l:Float):Color
Creates a color from normalized HSL components.
Parameters:
h | Hue in the |
|---|---|
s | Saturation in the |
l | Lightness in the |
Returns:
The resulting color.
staticinlinehsl2rgb(color:Color):Color
Converts an HSL color to RGB.
Parameters:
color | Source HSL color. |
|---|
Returns:
The converted RGB color.
staticinlinehsla(h:Int, s:Int, l:Int, a:Int = 255):Color
staticinlinehsla(h:Float, s:Float, l:Float, a:Float = 1.0):Color
staticinlinehsla(h:Int, s:Int, l:Int, a:Float = 1.0):Color
Creates a color from HSL components and an 8-bit alpha value.
Parameters:
h | Hue in degrees, usually |
|---|---|
s | Saturation in percent, usually |
l | Lightness in percent, usually |
a | Alpha channel in the |
Returns:
The resulting color.
staticinlinehsv(h:Float, s:Float, v:Float):Color
staticinlinehsv(h:Int, s:Int, v:Int):Color
Creates a color from normalized HSV components.
Parameters:
h | Hue in the |
|---|---|
s | Saturation in the |
v | Value in the |
Returns:
The resulting color.
staticinlinehsv2rgb(color:Color):Color
Converts an HSV color to RGB.
Parameters:
color | Source HSV color. |
|---|
Returns:
The converted RGB color.
staticinlinehsva(h:Int, s:Int, v:Int, a:Float = 1.0):Color
staticinlinehsva(h:Float, s:Float, v:Float, a:Float = 1.0):Color
staticinlinehsva(h:Int, s:Int, v:Int, a:Int = 255):Color
Creates a color from HSV components and a normalized alpha value.
Parameters:
h | Hue in degrees, usually |
|---|---|
s | Saturation in percent, usually |
v | Value in percent, usually |
a | Alpha channel in the |
Returns:
The resulting color.
staticinlinehue2rgb(hue:Float):Color
Converts a hue value into a fully saturated RGB color.
Parameters:
hue | Hue in the |
|---|
Returns:
The RGB color for that hue.
staticinlinemix(a:Color, b:Color, t:Float):Color
staticinlinemix(a:Color, b:Color, t:Int):Color
Linearly interpolates between two colors.
Interpolation is performed on normalized RGBA channels.
Parameters:
a | Start color. |
|---|---|
b | End color. |
t | Interpolation factor in the |
Returns:
The interpolated color.
staticinlinerandom():Color
Creates a random opaque color.
Each RGB channel is chosen independently in the 0.0..1.0 range.
Returns:
A random color with alpha set to 1.0.
staticinlinergb(r:Int, g:Int, b:Int):Color
staticinlinergb(r:Float, g:Float, b:Float):Color
Creates an opaque color from 8-bit RGB components.
Parameters:
r | Red channel in the |
|---|---|
g | Green channel in the |
b | Blue channel in the |
Returns:
A color with alpha set to 255.
staticinlinergb2hcv(color:Color):Color
Converts an RGB color to an HCV representation.
The returned vector is stored as (hue, chroma, value).
Parameters:
color | Source RGB color. |
|---|
Returns:
The converted HCV value.
staticinlinergb2hsl(rgb:Color):Color
Converts an RGB color to HSL.
Parameters:
rgb | Source RGB color. |
|---|
Returns:
The converted HSL color.
staticinlinergb2hsv(color:Color):Color
Converts an RGB color to HSV.
Parameters:
color | Source RGB color. |
|---|
Returns:
The converted HSV color.
staticinlinergb2srgb(rgb:Color):Color
Converts a linear RGB color to sRGB.
Parameters:
rgb | Source color in linear RGB space. |
|---|
Returns:
The converted sRGB color.
staticinlinergba(r:Int, g:Int, b:Int, a:Int = 255):Color
staticinlinergba(r:Float, g:Float, b:Float, a:Float = 1.0):Color
staticinlinergba(r:Int, g:Int, b:Int, a:Float = 1.0):Color
Creates a color from 8-bit RGBA components.
Parameters:
r | Red channel in the |
|---|---|
g | Green channel in the |
b | Blue channel in the |
a | Alpha channel in the |
Returns:
The resulting color.
staticinlinesrgb2rgb(srgb:Color):Color
Converts an sRGB color to linear RGB.
Parameters:
srgb | Source color in sRGB space. |
|---|
Returns:
The converted linear RGB color.
staticinlinetoColor(this:Int):Color
staticinlinetoString(this:Int):String
Converts this color to an 8-digit hexadecimal string.
The returned format is #AARRGGBB.
Returns:
The hexadecimal color string.