Skip to content

Lua colorlib

Lactozilla requested to merge lua-colorlib into next

Merge !2093 (merged) first.

Function Parameters Description Returns
color.paletteToRgb uint8 palette_index Converts a palette index into RGB values Red, green, blue values
color.rgbToPalette uint8 r, uint8 g, uint8 b, uint32 rgb, string web_color Converts RGB values into a palette index Palette index
color.hslToRgb uint8 h, uint8 s, uint8 l Converts an HSL color into RGB values Red, green, blue values
color.rgbToHsl uint8 r, uint8 g, uint8 b, uint32 rgb, string web_color Converts RGB values into HSL colors Hue, saturation, lightness values
color.rgbToHex uint8 r, uint8 g, uint8 b, [uint8 a], uint32 rgb, uint32 rgba, string web_color Converts an RGB(A) color into a web color The color in hexadecimal as a string (such as #6495ED or #FFF5EE40)
color.hexToRgb string web_color Converts a web color (such as #B22222 or #7F3) into RGBA values Red, green, blue (and alpha) values
color.packRgb uint8 r, uint8 g, uint8 b, uint32 rgb, string web_color Packs RGB values into a number representing a RGB color Number
color.packRgba uint8 r, uint8 g, uint8 b, uint8 a, uint32 rgb, uint32 rgba, string web_color Packs RGBA values into a number representing an RGBA color Number
color.unpackRgb uint32 rgb, uint32 rgba Unpacks a number representing an RGBA color into red, green, blue (and alpha) values Red, green, blue (and alpha) values

Examples

local rgb = color.packRgb(255, 0, 0)
local index = color.rgbToPalette(rgb) -- Returns palette index 35

local r, g, b = color.paletteToRgb(index) -- Returns 255, 0, 0
local h, s, l = color.rgbToHsl(r, g, b) -- Returns 0, 255, 128

h = 170 -- Makes a blue-ish color

r, g, b = color.hslToRgb(h, s, l) -- Returns 1, 1, 255
index = color.rgbToPalette(r, g, b) -- Returns palette index 152

hex = color.rgbToHex(r, g, b) -- Returns #0101FF
hex = color.rgbToHex(r, g, b, 128) -- Returns #0101FF80

hex = "#09C" -- Some very light blue
r, g, b = color.hexToRgb(hex) -- Returns 0, 153, 204

index = color.rgbToPalette(hex) -- Returns palette index 135
index = color.rgbToPalette("#0099CC") -- Same as above

index = color.rgbToPalette("#FA0") -- Some orange-ish color
index = color.rgbToPalette("FA0") -- Same as above
index = color.rgbToPalette("FFAA00") -- Same as above

Merge request reports