Skip to content

Instantly share code, notes, and snippets.

@boboboa32
Created January 15, 2013 09:08
Show Gist options
  • Save boboboa32/4537391 to your computer and use it in GitHub Desktop.
Save boboboa32/4537391 to your computer and use it in GitHub Desktop.
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