Created
May 17, 2012 17:47
-
-
Save nixpulvis/2720502 to your computer and use it in GitHub Desktop.
This if a function to convert hex strings into r, g, b color. This function returns multiple variables.
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
-- converts hex colors to 0-1 colors for use in World of Warcraft. | |
function V.HexToColor(hex) | |
local color = { } | |
if strlen(hex) == 6 or strlength(hex) == 8 then | |
for i = 1, 8, 2 do | |
if strsub(hex, i, i+1) == "" then print(strsub(hex, i, i+1)) break end | |
-- converting string to number 0-1 | |
tinsert(color, tonumber(strsub(hex, i, i+1), 16)/255) | |
end | |
else | |
error(hex.." is not a valid hex color") | |
end | |
return unpack(color) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment