That function expects decimal for s
(saturation) and v
(value), not percent. Divide by 100.
>>> import colorsys
# Using percent, incorrect
>>> test_color = colorsys.hsv_to_rgb(359,100,100)
>>> test_color
(100, -9900.0, -9900.0)
# Using decimal, correct
>>> test_color = colorsys.hsv_to_rgb(1,1,1)
>>> test_color
(1, 0.0, 0.0)
If you would like the non-normalized RGB tuple, here is a function to wrap the colorsys
function.
def hsv2rgb(h,s,v):
return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h,s,v))
Example functionality
>>> hsv2rgb(0.5,0.5,0.5)
(64, 128, 128)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…