Skip to content

Color ​

The Color value type: construct, convert and adjust colors.

Always available

No import needed. These names are in scope in every file.

Color struct ​

ts
struct Color

Color.fromUint ​

ts
static fromUint(n: uint): Color

A packed 0xRRGGBBAA number.

Color.fromArgb ​

ts
static fromArgb(n: uint): Color

A packed 0xAARRGGBB number.

Color.rgb ​

ts
static rgb(r: int, g: int, b: int): Color

Red, green and blue bytes (0-255), fully opaque.

Example

ts
const orange: Color = Color.rgb(255, 128, 0);
console.log(orange.r(), orange.g(), orange.b()); // 255 128 0

Color.rgba ​

ts
static rgba(r: int, g: int, b: int, a: int): Color

Red, green, blue and alpha bytes (0-255).

Example

ts
const glass: Color = Color.rgba(255, 255, 255, 128);
console.log(glass.a()); // 128

Color.rgbaf ​

ts
static rgbaf(r: float, g: float, b: float, a: float = 1.0): Color

Red, green, blue and alpha as 0-1 floats.

Color.hex ​

ts
static hex(s: string): Color

A hex string such as "#ff8800"; throws when it is not one.

Example

ts
const orange: Color = Color.hex("#ff8800");
console.log(orange.r(), orange.g(), orange.b()); // 255 136 0

Color.hsl ​

ts
static hsl(h: float, s: float, l: float): Color

Hue (degrees), saturation and lightness (0-1), fully opaque.

Color.hsla ​

ts
static hsla(h: float, s: float, l: float, a: float): Color

Hue, saturation, lightness and alpha (0-1).

Color.hsv ​

ts
static hsv(h: float, s: float, v: float, a: float = 1.0): Color

Hue (degrees), saturation and value (0-1).

Other members of Color ​

ts
value: uint32
static readonly WHITE: Color
static readonly BLACK: Color
static readonly TRANSPARENT: Color
static readonly RED: Color
static readonly GREEN: Color
static readonly BLUE: Color
static readonly YELLOW: Color
static readonly CYAN: Color
static readonly MAGENTA: Color
static readonly GRAY: Color
static readonly ORANGE: Color
static readonly PURPLE: Color
static tryHex(s: string): Color | null
r(): int
g(): int
b(): int
a(): int
rf(): float
gf(): float
bf(): float
af(): float
hue(): float
lightness(): float
saturation(): float
brightness(): float
luminance(): float
contrastRatio(other: Color): float
isDark(): boolean
isLight(): boolean
withR(v: int): Color
withG(v: int): Color
withB(v: int): Color
withA(v: int): Color
withAlpha(v: int): Color
fade(f: float): Color
hueShift(deg: float): Color
complement(): Color
saturate(amt: float): Color
desaturate(amt: float): Color
lighten(amt: float): Color
darken(amt: float): Color
brighten(f: float): Color
mix(other: Color, t: float): Color
lerp(other: Color, t: float): Color
tint(amt: float): Color
shade(amt: float): Color
invert(): Color
grayscale(): Color
premultiplied(): Color
toHex(): string
toHexRGB(): string
toCss(): string
toString(): string
toArgb(): uint
operator eq(other: Color): boolean

Generated from lang/color/index.tks in the ThicketScript repository.