Created
January 15, 2013 09:08
-
-
Save boboboa32/4537391 to your computer and use it in GitHub Desktop.
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
function HSVtoRGB(h, s, v) | |
local r, g, b | |
local i = math.floor(h * 6) | |
local f = h * 6 - i | |
local p = v * (1 - s) | |
local q = v * (1 - f * s) | |
local t = v * (1 - (1 - f) * s) | |
local switch = i % 6 | |
if switch == 0 then | |
r = v g = t b = p | |
elseif switch == 1 then | |
r = q g = v b = p | |
elseif switch == 2 then | |
r = p g = v b = t | |
elseif switch == 3 then | |
r = p g = q b = v | |
elseif switch == 4 then | |
r = t g = p b = v | |
elseif switch == 5 then | |
r = v g = p b = q | |
end | |
return math.floor(r*255), math.floor(g*255), math.floor(b*255) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment