wolfhacklua API 1.1 Forum

Colours

The format#

A colour is one integer written in hexadecimal as 0xRRGGBBAA: red, green, blue and alpha (opacity), one byte each, 00 to FF.

ColourValue
Opaque white0xFFFFFFFF
Opaque red0xFF0000FF
Half-transparent black0x00000080
Fully transparent0x00000000

The alpha is the last byte, which is the opposite of many web and game tools (0xAARRGGBB). If a colour comes out invisible or the wrong shade, check the order first.

Everywhere a colour is accepted you can also pass a table {r, g, b, a} with 0-255 values; a is optional.

Building and changing colours#

lua
local red   = color.rgba(255, 0, 0)            -- alpha defaults to 255
local web   = color.hex("#750851")             -- "#rrggbb" or "#rrggbbaa"
local green = color.hsv(1 / 3, 0.8, 1)         -- hue 0..1, saturation 0..1, value 0..1
local ghost = color.alpha(red, 0.25)           -- same colour at 25% opacity
local mix   = color.lerp(red, green, 0.5)      -- halfway between two colours
local r, g, b, a = color.split(mix)            -- back to channels

Animate the hue for a rainbow:

lua
events.on("draw", function()
  local c = color.hsv((time.now() * 0.2) % 1, 0.9, 1)
  draw.rect(20, 20, 200, 6, c, 3)
end)

Colour controls#

ui.color(id, label, default) shows a picker with alpha and returns the colour as an integer in the same format, so you can pass it straight to a draw call or save it:

lua
local accent = store.get("accent", 0x750851FF)

Matching the menu#

theme.current() returns the colours the menu uses right now (accent_rgba, background, card, border, text, text_dim, danger, success), so your drawing can follow the user's theme, including a theme your own script registered. See theme.

Fading#

For one colour use color.alpha(c, 0.5). To fade many things together, call draw.alpha(f) before drawing them and draw.alpha(1) after.

Readability#

Text on the game picture needs contrast against anything that might be behind it. Give floating text a dark background panel, the shadow or outline text option, or both; do not rely on a pale colour alone.

API 1.1 · source docs-src/pages/guide/colours.md