Skip to main content
An 8-bit RGBA color, channels 0–255. Global class, no import.
A plain number is always packed 0xAABBGGRR, red in the low byte. Fields r, g, b, a take integers 0–255, anything else throws.
ColorLike is a Color, a packed number, "#rgb", "#rgba", "#rrggbb", "#rrggbbaa", [r, g, b, a?] or { r, g, b, a? }.

Overview

Common

from, set, add, lerp…

Creating

fromHex, fromRGB, fromHSV, red()…

Adjusting

scale, withAlpha, withAlphaF, lerp.

Converting

toHex, toABGR, toHSV…

Common

Every argument takes any ColorLike, not just a Color. Only set() and normalize() change the value. Nothing changes its arguments. Color has no mul, div or normalize. Channel math clamps instead of wrapping, and lerp clamps t to 0–1.

Creating

The constructor with no arguments is opaque white.
new Color(255) is not grey or white. One number is the packed form, so it’s red with alpha 0.

fromHex


Parses rgb, rgba, rrggbb or rrggbbaa, with or without #. Anything else throws TypeError.

fromHSV


Hue in degrees, any value (wrapped). Saturation, value, lightness and alpha are 0–1, alpha defaults to 1.

Adjusting

withAlpha


The same color with a new alpha. withAlpha takes 0–255, withAlphaF takes 0–1. Both clamp.

Converting


Example

Health bar color from green to red, faded by distance.