datumhue.color.rgb
functiondatumhue.color.rgb(r: number, g: number, b: number) -> ColorColor from sRGB r, g, b (0..1).
namespaceColors7 functions
Construct sRGB colors. Call datumhue.color(...) with a hex string or r,g,b[,a] numbers, or use the named constructors.
datumhue.color.rgb(r: number, g: number, b: number) -> ColorColor from sRGB r, g, b (0..1).
datumhue.color.rgba(r: number, g: number, b: number, a: number) -> ColorColor from sRGB r, g, b, a (0..1).
datumhue.color.hex(s: string) -> ColorColor from a hex string (#RRGGBB or #RRGGBBAA).
print(datumhue.color.hex("#ff0000")) --> color(1.0, 0.0, 0.0, 1.0)
-- Eight digits carry alpha.
print(datumhue.color.hex("#ff000000")) --> color(1.0, 0.0, 0.0, 0.0)datumhue.color.hsl(h: number, s: number, l: number) -> ColorColor from hue (degrees — the CSS convention; hue is the API's one angle not in radians), saturation, lightness.
-- Hue in degrees; saturation and lightness 0 to 1.
print(datumhue.color.hsl(120, 1, 0.5)) --> color(0.0, 1.0, 0.0, 1.0)
print(datumhue.color.hsl(240, 1, 0.25)) --> color(0.0, 0.0, 0.5, 1.0)In the guide: Coordinates and units API conventions
datumhue.color.oklab(l: number, a: number, b: number) -> ColorColor from Oklab lightness, a, b (perceptual space).
-- Perceptual lightness: 0.5 is the gray halfway between black and
-- white to the eye, darker than sRGB 0.5.
local mid = datumhue.color.oklab(0.5, 0, 0)
print(string.format("%.2f", mid.r)) --> 0.39
-- Positive a leans red, positive b leans yellow.
local warm = datumhue.color.oklab(0.7, 0.1, 0.1)
print(warm.r > warm.b) --> truedatumhue.color.oklch(l: number, c: number, h: number) -> ColorColor from Oklch lightness, chroma, hue (degrees — the CSS convention, as in color.hsl; perceptual space).
-- Lightness 0 to 1, chroma from 0 (gray) up, hue in degrees.
local sage = datumhue.color.oklch(0.7, 0.1, 140)
local l, c, h = sage:to_oklch()
print(string.format("%.2f %.2f %.0f", l, c, h)) --> 0.70 0.10 140In the guide: Coordinates and units API conventions
datumhue.color.from_array(a: number[]) -> ColorColor from an {r, g, b[, a]} array (sRGB, 0..1; the inverse of color:to_array).
-- {r, g, b} or {r, g, b, a}, each 0 to 1.
local orange = datumhue.color.from_array({ 1, 0.5, 0 })
print(orange) --> color(1.0, 0.5, 0.0, 1.0)
local glass = datumhue.color.from_array({ 1, 0.5, 0, 0.5 })
print(glass) --> color(1.0, 0.5, 0.0, 0.5)| Value | Description |
|---|---|
"oklab" | |
"oklch" | |
"linear" | |
"srgb" | |
"hsl" |
Used by: Color:mix