Skip to content

tm.color ​

Hex and RGB helpers. Shared. The handle is tm.color.

lua
local rgb = tm.color.hexToRgb('#FF8800')   -- { r = 255, g = 136, b = 0 }
tm.color.rgbToHex(rgb)                      -- '#FF8800'
tm.color.rgbToLuminance(rgb)                -- 0 (black) to 1 (white)
FunctionNotes
hexToRgb(hex)Accepts #RRGGBB, RRGGBB and the short #RGB. Returns nil for anything else (wrong length, non-hex digits, not a string).
rgbToHex(rgb)Rounds and clamps each channel to 0..255 and returns upper case #RRGGBB.
rgbToLuminance(rgb)(0.299 r + 0.587 g + 0.114 b) / 255. Useful for choosing dark or light text over a color.