Builtin Library
README.md
color Module
Public Luau surface over the __color Internal FFI namespace — color
construction, conversion, and perceptual operations across sRGB / HSL /
HSV / Oklch / linear / hex.
Purpose
Wrap the raw __color.* FFI namespace (backed by bevy_color) in a
typed Luau table that gets auto-injected as _G.color via the
prelude. All public color values are { r, g, b, a } sRGB tables in
the 0-1 range — compatible with material.setColor, visuals.setTint,
and the rest of the engine surface.
Usage
-- Construction
local red = color.rgb(255, 0, 0) -- CSS-style 0-255
local teal = color.hsl(180, 0.5, 0.5)
local accent= color.oklch(0.7, 0.15, 30) -- perceptually uniform
local css = color.hex("#ff8800")
-- Perceptual operations (all done in Oklch)
local hover = color.lighten(base, 0.1)
local pop = color.saturate(base, 0.05)
local mid = color.mix(red, teal, 0.5)
local comp = color.complementary(red)
local trio = color.rotateHue(red, 120)
-- Conversion
local hex = color.toHex(base) -- "#rrggbb" / "#rrggbbaa"
local okl = color.toOklch(base) -- { l, c, h, a }
local gpu = color.toLinear(base) -- linear RGB for shaders
Exports
color.rgb/color.rgba— CSS-style 0-255 constructors.color.hsl/color.hsla/color.hsv— HSL / HSV constructors.color.oklch— Oklch perceptual constructor.color.hex— parse hex strings (3 / 4 / 6 / 8 digits,#optional).color.linear— linear-RGB constructor, output as sRGB.color.mix/color.mixRgb— perceptual / linear blends.color.lighten/color.darken/color.saturate/color.desaturate— Oklch tweaks.color.withAlpha— alpha override.color.complementary/color.rotateHue— hue rotation in Oklch.color.toHex/color.toHsl/color.toOklch/color.toLinear— conversions out.