local function colorfromHSV(H, S, V) local R, G, B local vr, vg, vb if S == 0 then vr = V vg = V vb = V else local vh = H * 6 if vh == 6 then vh = 0 end local vi = math.floor(vh) local v1 = V * (1 - S) local v2 = V * (1 - S * (vh - vi)) local v3 = V * (1 - S * (1 - (vh - vi))) if vi == 0 then vr = V vg = v3 vb = v1 elseif vi == 1 then vr = v2 vg = V vb = v1 elseif vi == 2 then vr = v1 vg = V vb = v3 elseif vi == 3 then vr = v1 vg = v2 vb = V elseif vi == 4 then vr = v3 vg = v1 vb = V else vr = V vg = v1 vb = v2 end end R = math.floor(vr * 255) G = math.floor(vg * 255) B = math.floor(vb * 255) return cd.EncodeColor(R, G, B), R, G, B, vr, vg, vb end