Created
December 22, 2012 03:47
-
-
Save jasonbradley/4357406 to your computer and use it in GitHub Desktop.
Lua convert HEX to RGB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Util:hex2rgb(hex) | |
| hex = hex:gsub("#","") | |
| return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)) | |
| end |
Thank you very much!
What if I want to convert a color like "#ccc"?
Syntax sugar version and works too for short HEX
https://gist.github.com/fernandohenriques/12661bf250c8c2d8047188222cab7e28
I still show how use function in Corona SDK.
❤
thanks :)
With alpha channel and short hex support, fractional(0.0,1.0) and integer(0,255) outputs, validation
https://gist.github.com/saantonandre/f641a6e1e9215543b31b4fafa733397c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this! :)