wolfhacklua API 1.1 Forum

color

Build, split, blend and fade colours.

since 1.0no permission needed

A colour is an integer 0xRRGGBBAA (red, green, blue, alpha, one byte each), so 0xFF0000FF is opaque red and 0xFFFFFF80 is half-transparent white. Every function that takes a colour also accepts a table {r, g, b, a} with 0-255 values. See colours.

Reference#

color.rgba#since 1.0

color.rgba(r: integer, g: integer, b: integer, a?: integer): integer

Builds a colour from channels.

ParameterTypeDescription
rintegerRed, 0-255.
gintegerGreen, 0-255.
bintegerBlue, 0-255.
a optionalintegerAlpha, 0-255. default 255
ReturnsDescription
integerThe colour.
lua
local red = color.rgba(255, 0, 0)

color.hsv#since 1.0

color.hsv(h: number, s: number, v: number, a?: integer): integer

Builds a colour from hue, saturation and value. Animate the hue for a rainbow.

ParameterTypeDescription
hnumberHue, 0 to 1.
snumberSaturation, 0 to 1.
vnumberValue, 0 to 1.
a optionalintegerAlpha, 0-255. default 255
ReturnsDescription
integerThe colour.
lua
local c = color.hsv((time.now() * 0.2) % 1, 0.8, 1)

color.hex#since 1.0

color.hex(hex: string): integer

Parses a web colour string.

ParameterTypeDescription
hexstring"#rrggbb" or "#rrggbbaa".
ReturnsDescription
integerThe colour.

color.split#since 1.0

color.split(c: integer): integer, integer, integer, integer

Takes a colour apart.

ParameterTypeDescription
cintegerA colour.
ReturnsDescription
integerRed.
integerGreen.
integerBlue.
integerAlpha.

color.lerp#since 1.0

color.lerp(a: integer, b: integer, t: number): integer

Blends two colours.

ParameterTypeDescription
aintegerStart colour.
bintegerEnd colour.
tnumberProgress 0..1.
ReturnsDescription
integerThe blend.

color.alpha#since 1.0

color.alpha(c: integer, alpha: number): integer

Changes only the opacity of a colour.

ParameterTypeDescription
cintegerA colour.
alphanumberNew opacity from 0 to 1.
ReturnsDescription
integerThe colour with that alpha.
lua
draw.rect(10, 10, 100, 20, color.alpha(0xFFFFFFFF, 0.25))
API 1.1 · source docs-src/api/color.json