Skip to content

lcd.RGB

since 1.1.0

Get a color from red, green and blue values with optional alpha opacity.

local color = lcd.RGB(red, green, blue[, alpha])

Parameters

Name Type Required Description
red integer yes red value(0 - 255)
green integer yes green value(0 - 255)
blue integer yes blue value(0 - 255)
alpha number optional alpha value(0 - 1.0)

Returns

color (integer)

Examples

-- build colors once, at file level, and reuse them in paint()
local ORANGE  = lcd.RGB(255, 128, 0)
local SHADOW  = lcd.RGB(0, 0, 0, 0.4)      -- 40 % opaque black
local WARNING = lcd.RGB(0xE6, 0x32, 0x32)  -- hex components work too

local function paint(widget)
  lcd.color(widget.alarm and WARNING or ORANGE)
  lcd.drawFilledRectangle(0, 0, 20, 20)
end

Tip

lcd.RGB is one of the most-called functions in real scripts. Calling it with constant arguments inside paint repeats work every frame; compute constant colors once.

Used in

Real-world usage

Called 637 times across 11 open-source Ethos Lua projects. A few short excerpts:
lcd.color(lcd.RGB(40, 40, 40))

src/bmfa-caller/widget_impl.lua:57

lcd.color(lcd.RGB(190, 190, 190))

src/ethos-arcade/games/gulaxian/game.lua:668

local skyColor = lcd.RGB(70, 130, 180)

src/rfsuite/widgets/dashboard/objects/navigation/ah.lua:140