Module color
Color utilities module
Functions
hexToRGB (hex) | Convert an hexadecimal color to rgb value |
getContrastColor (hex) | Check if a color need to be paired to a high or low contrast color according to its luminance |
Functions
- hexToRGB (hex)
-
Convert an hexadecimal color to rgb value
Parameters:
- hex string The hexadecimal color as a string
Returns:
-
table # A table with three keys, r, g, and b containing numbers
Raises:
error if hex is not a string
error if hex is not valid (no #, more than 6 values, invalid values)Usage:
print(hexToRGB("#32a852")) -- -> { r = 50, g = 168, b = 82 }
- getContrastColor (hex)
-
Check if a color need to be paired to a high or low contrast color according to its luminance
Parameters:
- hex string The hexadecimal color as a string
Returns:
-
“dark”|“light” # What the contrast should be
Raises:
error if hex is not a string
error if hex is not valid (no #, more than 6 values, invalid values)Usage:
print(getContrastColor("#000000")) -- black -> 'light' contrast print(getContrastColor("#ffffff")) -- white -> 'dark' contrast