Convert HEX or RGB values into decimal rgb color values, compatible with Corona and Defold format, (numbers from 0 to 1).
-
Put lua-color-converter.lua into your project directory
-
Load it in your scripts when neccesary:
local color = require("lua-color-converter")
- Use it to convert from hex:
color.hex("ff00ff") -- 0.5, 0, 0.5
-- You can include "#" in your string if needed
color.hex("#ff00ff") -- 0.5, 0, 0.5
.. and to convert from regular byte rgb:
-- r,g,b
color.rgb(255, 0, 255) -- 0.5, 0, 0.5
You can use one more argument to set alpha channel:
color.hex("ff00ff", 0.5) --alpha set to 50%
color.rgb(255, 0, 255, 75) --alpha set to 75%
local myText = display.newText( "example from Corona Docs", 0, 0, native.systemFontBold, 12 )
myText:setFillColor( color.hex("#ff10ae") )
go.set("#label", "color", vmath.vector4(color.rgb(255, 16, 174, 1))