Last active
June 19, 2022 11:00
-
-
Save fernandohenriques/12661bf250c8c2d8047188222cab7e28 to your computer and use it in GitHub Desktop.
Corona SDK use just RGB colors. This function convert HEX to RGB.
This file contains 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
-- 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 | |
This file contains 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
-- 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