Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rgb2hsv in Coffeescript
rgb2hsv (r,g,b) ->
r=r/255
g=g/255
b=b/255
max = Math.max(r,g,b)
min = Math.min(r,g,b)
v = max
d = max - min
s = if max == 0 then 0 else d/max
h = if max == min then 0
else
switch max
when r then h = (g-b) / (d + ( if g < b then 6 else 0))
when g then h = (b-r) / d + 2
when b then h = (r-g) / d + 4
h / 6
[h,s,v]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.