Welcome, guest | Sign In | My Account | Store | Cart
```def hsvToRGB(h, s, v):
"""Convert HSV color space to RGB color space

@param h: Hue
@param s: Saturation
@param v: Value
return (r, g, b)
"""
import math
hi = math.floor(h / 60.0) % 6
f =  (h / 60.0) - math.floor(h / 60.0)
p = v * (1.0 - s)
q = v * (1.0 - (f*s))
t = v * (1.0 - ((1.0 - f) * s))
return {
0: (v, t, p),
1: (q, v, p),
2: (p, v, t),
3: (p, q, v),
4: (t, p, v),
5: (v, p, q),
}[hi]

def rgbToHSV(r, g, b):
"""Convert RGB color space to HSV color space

@param r: Red
@param g: Green
@param b: Blue
return (h, s, v)
"""
maxc = max(r, g, b)
minc = min(r, g, b)
colorMap = {
id(r): 'r',
id(g): 'g',
id(b): 'b'
}
if colorMap[id(maxc)] == colorMap[id(minc)]:
h = 0
elif colorMap[id(maxc)] == 'r':
h = 60.0 * ((g - b) / (maxc - minc)) % 360.0
elif colorMap[id(maxc)] == 'g':
h = 60.0 * ((b - r) / (maxc - minc)) + 120.0
elif colorMap[id(maxc)] == 'b':
h = 60.0 * ((r - g) / (maxc - minc)) + 240.0
v = maxc
if maxc == 0.0:
s = 0.0
else:
s = 1.0 - (minc / maxc)
return (h, s, v)
```