Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Created May 17, 2012 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixpulvis/2720502 to your computer and use it in GitHub Desktop.
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.
-- 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