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

staticHSL:Vec3

HSL channels as a normalized Vec3 in (h, s, l) order.

staticHSLA:Vec4

HSLA channels as a normalized Vec4 in (h, s, l, a) order.

staticHSV:Vec3

HSV channels as a normalized Vec3 in (h, s, v) order.

staticHSVA:Vec4

HSVA channels as a normalized Vec4 in (h, s, v, a) order.

staticRGB:Vec3

RGB channels as a normalized Vec3 in (r, g, b) order.

staticRGBA:Vec4

RGBA channels as a normalized Vec4 in (r, g, b, a) order.

statica:Float

Alpha channel in the 0.0..1.0 range.

staticb:Float

Blue channel in the 0.0..1.0 range.

staticg:Float

Green channel in the 0.0..1.0 range.

statich:Float

Hue component in the 0.0..1.0 range.

0.0 and 1.0 represent the same hue.

staticr:Float

Red channel in the 0.0..1.0 range.

statics:Float

Saturation component in the 0.0..1.0 range of the HSV color model.

staticv:Float

Value component in the 0.0..1.0 range of the HSV color model.

Static methods

@:fromstaticinlinefromColor(value:Color):Color

Converts a kha.Color to Color.

Parameters:

value

Source kha.Color.

Returns:

The converted color.

@:fromstaticinlinefromString(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.

@:fromstaticinlinefromVec3(value:Vec3):Color

Creates a color from a normalized RGB vector.

Parameters:

value

RGB channels in (r, g, b) order.

Returns:

The resulting color.

@:fromstaticinlinefromVec4(value:Vec4):Color

Creates a color from a normalized RGBA vector.

Parameters:

value

RGBA channels in (r, g, b, a) order.

Returns:

The resulting color.

staticinlinehsl(h:Float, s:Float, l:Float):Color

Creates a color from normalized HSL components.

Parameters:

h

Hue in the 0.0..1.0 range.

s

Saturation in the 0.0..1.0 range.

l

Lightness in the 0.0..1.0 range.

Returns:

The resulting color.

staticinlinehsl2rgb(color:Color):Color

Converts an HSL color to RGB.

Parameters:

color

Source HSL color.

Returns:

The converted RGB color.

@:value({ a : 255 })staticinlinehsla(h:Int, s:Int, l:Int, a:Int = 255):Color

@:value({ a : 1.0 })staticinlinehsla(h:Float, s:Float, l:Float, a:Float = 1.0):Color

@:value({ a : 1.0 })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 0..360.

s

Saturation in percent, usually 0..100.

l

Lightness in percent, usually 0..100.

a

Alpha channel in the 0..255 range.

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 0.0..1.0 range.

s

Saturation in the 0.0..1.0 range.

v

Value in the 0.0..1.0 range.

Returns:

The resulting color.

staticinlinehsv2rgb(color:Color):Color

Converts an HSV color to RGB.

Parameters:

color

Source HSV color.

Returns:

The converted RGB color.

@:value({ a : 1.0 })staticinlinehsva(h:Int, s:Int, v:Int, a:Float = 1.0):Color

@:value({ a : 1.0 })staticinlinehsva(h:Float, s:Float, v:Float, a:Float = 1.0):Color

@:value({ a : 255 })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 0..360.

s

Saturation in percent, usually 0..100.

v

Value in percent, usually 0..100.

a

Alpha channel in the 0.0..1.0 range.

Returns:

The resulting color.

staticinlinehue2rgb(hue:Float):Color

Converts a hue value into a fully saturated RGB color.

Parameters:

hue

Hue in the 0.0..1.0 range.

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 0.0..1.0 range.

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 0..255 range.

g

Green channel in the 0..255 range.

b

Blue channel in the 0..255 range.

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.

@:value({ a : 255 })staticinlinergba(r:Int, g:Int, b:Int, a:Int = 255):Color

@:value({ a : 1.0 })staticinlinergba(r:Float, g:Float, b:Float, a:Float = 1.0):Color

@:value({ a : 1.0 })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 0..255 range.

g

Green channel in the 0..255 range.

b

Blue channel in the 0..255 range.

a

Alpha channel in the 0..255 range.

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.

@:tostaticinlinetoColor(this:Int):Color

Converts this value to kha.Color.

Returns:

The same color as a kha.Color.

@:tostaticinlinetoString(this:Int):String

Converts this color to an 8-digit hexadecimal string.

The returned format is #AARRGGBB.

Returns:

The hexadecimal color string.

@:tostaticinlinetoVec3(this:Int):Vec3

Converts this color to a normalized RGB vector.

Returns:

A Vec3 in (r, g, b) order.

@:tostaticinlinetoVec4(this:Int):Vec4

Converts this color to a normalized RGBA vector.

Returns:

A Vec4 in (r, g, b, a) order.

Variables

@:value(cast 0xff000000)@:impl@:enuminlineread onlyBlack:Color = 0xff000000

Fully opaque black.

@:value(cast 0xff0000ff)@:impl@:enuminlineread onlyBlue:Color = 0xff0000ff

Fully opaque blue.

@:value(cast 0xff00ffff)@:impl@:enuminlineread onlyCyan:Color = 0xff00ffff

Fully opaque cyan.

@:value(cast 0xff00ff00)@:impl@:enuminlineread onlyGreen:Color = 0xff00ff00

Fully opaque green.

@:value(cast 0xffff00ff)@:impl@:enuminlineread onlyMagenta:Color = 0xffff00ff

Fully opaque magenta.

@:value(cast 0xffffa500)@:impl@:enuminlineread onlyOrange:Color = 0xffffa500

Fully opaque orange.

@:value(cast 0xffffc0cb)@:impl@:enuminlineread onlyPink:Color = 0xffffc0cb

Fully opaque pink.

@:value(cast 0xff800080)@:impl@:enuminlineread onlyPurple:Color = 0xff800080

Fully opaque purple.

@:value(cast 0xffff0000)@:impl@:enuminlineread onlyRed:Color = 0xffff0000

Fully opaque red.

@:value(cast 0x00000000)@:impl@:enuminlineread onlyTransparent:Color = 0x00000000

Fully transparent black.

@:value(cast 0xffffffff)@:impl@:enuminlineread onlyWhite:Color = 0xffffffff

Fully opaque white.

@:value(cast 0xffffff00)@:impl@:enuminlineread onlyYellow:Color = 0xffffff00

Fully opaque yellow.