Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- M.rgb_to_hsv = function(r, g, b)
- r, g, b = (r / 255), (g / 255), (b / 255)
- local mx = math.max(r, g, b)
- local mn = math.min(r, g, b)
- local h, s
- if mx == mn then
- h = 0
- d = 0
- else
- local d = mx - mn
- if mx == r then h = (g - b) / d + (g < b and 6 or 0)
- elseif mx == g then h = (b - r) / d + 2
- elseif mx == b then h = (r - g) / d + 4 end
- h = h / 6
- end
- s = (mx == 0) and 0 or (d / mx)
- return h, s, mx
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement