1import colorsys
2
3def hsv2rgb(self, h,s,v):
4 return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h/360,s/100,v/100))
5
6# H S V values should be between 0 and 1.
7# If the colors are already normalised(between 0 and 1) you don't have to divide em in the return statement.
8
9# - sabz
1# RGB TO HSV
2
3import colorsys
4
5def rgb2hsv(self, r_or_color, g = 0, b = 0, a = None):
6 '''its in the name'''
7 if type(r_or_color).__name__ == "tuple":
8 if len(r_or_color) == 4:
9 r,g,b,a = r_or_color
10 else:
11 r,g,b = r_or_color
12 else: r = r_or_color
13 h,s,v = colorsys.rgb_to_hsv(r / 255.0, g / 255.0, b / 255.0)
14 if a != None:
15 return (h * 100, s * 100, v * 100, a)
16 return (int(h * 100), int(s * 100), int(v * 100))
17
18# - sabz