License New BSD license
Lines 35
Keywords
Colors (2) HSV (2) RGB (2)
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Easily highlight source code for your blog with our Syntax Highlighter. Join Siafoo Now or Learn More

HSV to RGB Atom Feed 1

# 's
 1def HSVtoRGB(hsv):
2 rgb = [0, 0, 0] # pass through alpha channel
3
4 hsv[0] /= 60
5
6 if hsv[1] == 0:
7 return tuple([hsv[2], hsv[2], hsv[2]])
8
9 i = int(hsv[0])
10 f = hsv[0] - i #Decimal bit of hue
11 p = hsv[2] * (1 - hsv[1])
12 q = hsv[2] * (1 - hsv[1] * f)
13 t = hsv[2] * (1 - hsv[1] * (1 - f))
14
15 if i == 0:
16 rgb[0] = hsv[2]
17 rgb[1] = t
18 rgb[2] = p
19 elif i == 1:
20 rgb[0] = q
21 rgb[1] = hsv[2]
22 rgb[2] = p
23 elif i == 2:
24 rgb[0] = p
25 rgb[1] = hsv[2]
26 rgb[2] = t
27 elif i == 3:
28 rgb[0] = p
29 rgb[1] = q
30 rgb[2] = hsv[2]
31 elif i == 4:
32 rgb[0] = t
33 rgb[1] = p
34 rgb[2] = hsv[2]
35 elif i == 5:
36 rgb[0] = hsv[2]
37 rgb[1] = p
38 rgb[2] = q
39
40 return tuple(rgb)