Skip to content

rgbm

The rgbm type is the standard color primitive in CSP, consisting of r, g, and b channels plus a mult (multiplier) channel that serves different roles depending on context.

Initialize a color with specific values or from a hex string.

-- black (0, 0, 0) with mult=0
local c1 = rgbm()
-- solid red (1, 0, 0) with full opacity (1)
local c2 = rgbm(1, 0, 0, 1)
-- create from a hex string
local c3 = rgbm("#FF5500")

The rgbm type is highly flexible and optimized via FFI. It supports standard mathematical operators (+, -, *, /) and equality checks (==).

Multiplying an rgbm by a number scales all four components, while multiplying by another rgbm performs per-channel multiplication. Like vec3, these are C-style structures; for high-frequency updates, use in-place methods such as :setLerp() instead of arithmetic operators to reduce allocations.

PropertyTypeDescription
rnumberRed channel (typically 0–1).
gnumberGreen channel (typically 0–1).
bnumberBlue channel (typically 0–1).
multnumberMultiplier (Alpha or Intensity).
rgbrgbReturns the standard 3-channel rgb component.
MethodDescription
:luminance()Returns the perceived brightness of the color.
:hex()Returns a CSS-style hex string (e.g., #AARRGGBB).
:hsv()Converts the color to an hsv primitive.
:set(rgb, mult)Updates the color values in place.
:setLerp(c1, c2, m)Smoothly blends between two colors in place.

Using the multiplier as an alpha channel to pulse the opacity of a rectangle.

local myColor = rgbm.colors.blue:clone()
function script.update()
-- pulse the alpha (mult) between 0.0 and 1.0
myColor.mult = math.sin(ac.getSim().gameTime) * 0.5 + 0.5
ui.drawRectFilled(vec2(10, 10), vec2(60, 60), myColor)
end