Skip to content

Instantly share code, notes, and snippets.

@jasonbradley
Created December 22, 2012 03:47
Show Gist options
  • Save jasonbradley/4357406 to your computer and use it in GitHub Desktop.
Save jasonbradley/4357406 to your computer and use it in GitHub Desktop.
Lua convert HEX to RGB
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
@Sevenanths
Copy link

Thank you very much!

@siasur
Copy link

siasur commented Apr 27, 2016

What if I want to convert a color like "#ccc"?

@fernandohenriques
Copy link

fernandohenriques commented Nov 27, 2017

Syntax sugar version and works too for short HEX

https://gist.github.com/fernandohenriques/12661bf250c8c2d8047188222cab7e28

I still show how use function in Corona SDK.

@TheXSVV
Copy link

TheXSVV commented Aug 29, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment