Skip to main content
The Color class represents an RGBA color value where each channel (r, g, b, a) is a floating-point number in the range 0 to 1. You use Color whenever you need to tint objects, set dialog backgrounds, drive visual effects, or blend between two colors over time. RollingQuest also provides a collection of pre-built static colors — like Color.red and Color.white — so you don’t have to remember the exact component values for common colors. All component properties are read-only after construction; create a new Color to change a value.

Constructors

-- Full RGBA
local red  = Color.new(1, 0, 0, 1)

-- RGB only — alpha defaults to fully opaque (1)
local blue = Color.new(0, 0, 1)

-- Grayscale — all three channels are set to the same value
local mid  = Color.new(0.5)

-- Grayscale with explicit alpha
local fog  = Color.new(0.8, 0.4)

-- No arguments — returns black (0, 0, 0, 0)
local blank = Color.new()
SignatureDescription
Color.new(r, g, b, a)Creates a color with explicit red, green, blue, and alpha values.
Color.new(r, g, b)Creates a color with the given channels; alpha is 1 (fully opaque).
Color.new(grayscale)Sets R, G, and B to grayscale; alpha is 1.
Color.new(grayscale, alpha)Sets R, G, and B to grayscale with the given alpha.
Color.new()Returns a transparent black (0, 0, 0, 0).

Instance Properties

PropertyTypeRead-onlyDescription
rnumberYesThe red channel (0–1).
gnumberYesThe green channel (0–1).
bnumberYesThe blue channel (0–1).
anumberYesThe alpha (opacity) channel (0–1).
grayscalenumberYesThe perceptual grayscale value of the color.
maxColorComponentnumberYesThe highest value among R, G, and B.
linearColorYesThis color converted to linear color space.
gammaColorYesThis color converted to gamma color space.
You can also index a Color by integer (c[1] → R, c[2] → G, c[3] → B, c[4] → A) for both read and write access.

Static Color Constants

These pre-built colors are available without constructing anything.
ConstantRGBA
Color.red(1, 0, 0, 1)
Color.green(0, 1, 0, 1)
Color.blue(0, 0, 1, 1)
Color.white(1, 1, 1, 1)
Color.black(0, 0, 0, 1)
Color.yellow(1, 0.92, 0.016, 1)
Color.cyan(0, 1, 1, 1)
Color.magenta(1, 0, 1, 1)
Color.gray(0.5, 0.5, 0.5, 1)
Color.greyAlias for Color.gray.
Color.clear(0, 0, 0, 0) — fully transparent.

Static Methods

lerp

Linearly interpolates between color a and color b by the clamped factor t (0 → a, 1 → b). Each channel is interpolated independently.
--- @param a Color
--- @param b Color
--- @param t number
--- @return Color
function Color.lerp(a, b, t)

lerpUnclamped

Same as lerp but t is not clamped, allowing extrapolation beyond the two endpoints.
--- @param a Color
--- @param b Color
--- @param t number
--- @return Color
function Color.lerpUnclamped(a, b, t)

Usage Examples

Creating custom colors

-- A semi-transparent orange
local orange = Color.new(1.0, 0.5, 0.0, 0.75)

-- Pure white (shorthand via static constant)
local white = Color.white

-- A dark gray using the grayscale constructor
local darkGray = Color.new(0.2)

Blending between two colors over time

local t = 0

function OnUpdate(delta)
    t = t + delta * 0.5   -- takes 2 seconds to blend fully
    if t > 1 then t = 1 end

    local blended = Color.lerp(Color.blue, Color.red, t)
    self.renderer.color = blended
end

Using a Color with the Dialog namespace

Pass a Color value as the background parameter when showing a dialog so your UI fits the scene’s mood.
local bgColor = Color.new(0.1, 0.05, 0.2, 0.9)  -- deep purple, slightly transparent

Dialog.show({
    text       = "A mysterious voice whispers from the dark...",
    background = bgColor,
    textColor  = Color.white,
})

Reading individual channels

local c = Color.new(0.8, 0.3, 0.1, 1.0)

print("Red:   " .. tostring(c.r))         -- 0.8
print("Green: " .. tostring(c.g))         -- 0.3
print("Blue:  " .. tostring(c.b))         -- 0.1
print("Gray:  " .. tostring(c.grayscale)) -- perceptual average