Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2011
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. -----------------------------
  2. -- HSV > RGB color conversion
  3. -----------------------------
  4. -- adapted from:
  5. -- http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
  6. -----------------------------
  7.  
  8. function HSVtoRGB(h, s, v)
  9.  
  10.   local r, g, b
  11.  
  12.   local i = math.floor(h * 6)
  13.   local f = h * 6 - i
  14.   local p = v * (1 - s)
  15.   local q = v * (1 - f * s)
  16.   local t = v * (1 - (1 - f) * s)
  17.  
  18.   local switch = i % 6
  19.   if switch == 0 then
  20.     r = v g = t b = p
  21.   elseif switch == 1 then
  22.     r = q g = v b = p
  23.   elseif switch == 2 then
  24.     r = p g = v b = t
  25.   elseif switch == 3 then
  26.     r = p g = q b = v
  27.   elseif switch == 4 then
  28.     r = t g = p b = v
  29.   elseif switch == 5 then
  30.     r = v g = p b = q
  31.   end
  32.  
  33.   return math.floor(r*255), math.floor(g*255), math.floor(b*255)
  34.  
  35. end
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement