Skip to content

Commit bbbcfc3

Browse files
committed
Returns RGB[0-255]
1 parent 2b7058c commit bbbcfc3

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

colorsys.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#This implements a chopped down relevant version of the colorsys library
2-
#to add HLS and HSV to RGB support
3-
#Returned values will be a 0-1 float and will need to be returned to 0-255 integer value.
2+
#to add HLS and HSV to RGB support. Script altered to return RGB[0-255]
43

54
__all__ = ["hls_to_rgb","hsv_to_rgb"]
65

@@ -23,7 +22,7 @@ def hls_to_rgb(h, l, s):
2322
else:
2423
m2 = l+s-(l*s)
2524
m1 = 2.0*l - m2
26-
return (_v(m1, m2, h+ONE_THIRD), _v(m1, m2, h), _v(m1, m2, h-ONE_THIRD))
25+
return (int(_v(m1, m2, h+ONE_THIRD)*255), int(_v(m1, m2, h)*255), int(_v(m1, m2, h-ONE_THIRD)*255))
2726

2827
def _v(m1, m2, hue):
2928
hue = hue % 1.0
@@ -51,15 +50,15 @@ def hsv_to_rgb(h, s, v):
5150
t = v*(1.0 - s*(1.0-f))
5251
i = i%6
5352
if i == 0:
54-
return v, t, p
53+
return int(v * 255), int(t *255), int(p * 255)
5554
if i == 1:
56-
return q, v, p
55+
return int(q * 255), int(v *255), int(p * 255)
5756
if i == 2:
58-
return p, v, t
57+
return int(p * 255), int(v *255), int(t * 255)
5958
if i == 3:
60-
return p, q, v
59+
return int(p * 255), int(q *255), int(v * 255)
6160
if i == 4:
62-
return t, p, v
61+
return int(t * 255), int(p *255), int(v * 255)
6362
if i == 5:
64-
return v, p, q
63+
return int(v * 255), int(p *255), int(q * 255)
6564
# Cannot get here

0 commit comments

Comments
 (0)