Skip to content

Instantly share code, notes, and snippets.

@fernandohenriques
Last active June 19, 2022 11:00
Show Gist options
  • Save fernandohenriques/12661bf250c8c2d8047188222cab7e28 to your computer and use it in GitHub Desktop.
Save fernandohenriques/12661bf250c8c2d8047188222cab7e28 to your computer and use it in GitHub Desktop.
Corona SDK use just RGB colors. This function convert HEX to RGB.
-- path for this file: src/utils/
function hex2rgb (hex)
local hex = hex:gsub("#","")
if hex:len() == 3 then
return (tonumber("0x"..hex:sub(1,1))*17)/255, (tonumber("0x"..hex:sub(2,2))*17)/255, (tonumber("0x"..hex:sub(3,3))*17)/255
else
return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255
end
end
-- main.lua is required in root folder on projects with Corona SDK
require('src.utils.hex2rgb')
display.setDefault("background",hex2rgb('#1b1a1a'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment