License New BSD license
Lines 24
Keywords
Colors (2) HSV (2) RGB (2)
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Need a quick chart or graph for your blog? Try our reStructured Text renderer. Join Siafoo Now or Learn More

RGB to HSV Atom Feed 0

# 's
 1def RGBtoHSV(rgb):
2 hsv = [0, 0, 0]
3 trgb = list(rgb)
4 trgb.sort()
5
6 min = trgb[0]
7 max = trgb[2]
8
9 delta = float(max - min)
10 hsv[2] = max
11
12 if delta == 0:
13 # r = g = b = 0 # s = 0, v is undefined
14 hsv[1] = 0
15 hsv[0] = - 1
16 else:
17 hsv[1] = delta / max
18
19 if rgb[0] == max:
20 hsv[0] = (rgb[1] - rgb[2]) / delta # between yellow & magenta
21 elif rgb[1] == max:
22 hsv[0] = 2 + (rgb[2] - rgb[0]) / delta # between cyan & yellow
23 else:
24 hsv[0] = 4 + (rgb[0] - rgb[1]) / delta # between magenta & cyan
25
26 hsv[0] *= 60 # degrees
27 if hsv[0] < 0:
28 hsv[0] += 360
29
30 return hsv