Fix for issue 31. hsl(a) processing on floats.
This commit is contained in:
parent
19ed65645d
commit
cb291c5e80
|
@ -157,11 +157,7 @@ class Color():
|
||||||
return self.hsla(*args)
|
return self.hsla(*args)
|
||||||
elif len(args) == 3:
|
elif len(args) == 3:
|
||||||
h, s, l = args
|
h, s, l = args
|
||||||
if isinstance(l, str):
|
rgb = colorsys.hls_to_rgb(int(h) / 360.0, utility.pc_or_float(l), utility.pc_or_float(s))
|
||||||
l = int(l.strip('%'))
|
|
||||||
if isinstance(s, str):
|
|
||||||
s = int(s.strip('%'))
|
|
||||||
rgb = colorsys.hls_to_rgb(int(h) / 360.0, l / 100.0, s / 100.0)
|
|
||||||
color = (utility.convergent_round(c * 255) for c in rgb)
|
color = (utility.convergent_round(c * 255) for c in rgb)
|
||||||
return self._rgbatohex(color)
|
return self._rgbatohex(color)
|
||||||
raise ValueError('Illegal color values')
|
raise ValueError('Illegal color values')
|
||||||
|
@ -175,13 +171,9 @@ class Color():
|
||||||
"""
|
"""
|
||||||
if len(args) == 4:
|
if len(args) == 4:
|
||||||
h, s, l, a = args
|
h, s, l, a = args
|
||||||
if isinstance(l, str):
|
rgb = colorsys.hls_to_rgb(int(h) / 360.0, utility.pc_or_float(l), utility.pc_or_float(s))
|
||||||
l = int(l.strip('%'))
|
|
||||||
if isinstance(s, str):
|
|
||||||
s = int(s.strip('%'))
|
|
||||||
rgb = colorsys.hls_to_rgb(int(h) / 360.0, l / 100.0, s / 100.0)
|
|
||||||
color = [float(utility.convergent_round(c * 255)) for c in rgb]
|
color = [float(utility.convergent_round(c * 255)) for c in rgb]
|
||||||
color.append(utility.convergent_round(float(a[:-1]) / 100.0, 2))
|
color.append(utility.pc_or_float(a))
|
||||||
return "rgba(%s,%s,%s,%s)" % tuple(color)
|
return "rgba(%s,%s,%s,%s)" % tuple(color)
|
||||||
raise ValueError('Illegal color values')
|
raise ValueError('Illegal color values')
|
||||||
|
|
||||||
|
|
|
@ -278,6 +278,16 @@ def convergent_round(value, ndigits=0):
|
||||||
return math.ceil(nearest_even)
|
return math.ceil(nearest_even)
|
||||||
return round(value, ndigits)
|
return round(value, ndigits)
|
||||||
|
|
||||||
|
def pc_or_float(s):
|
||||||
|
""" Utility function to process strings that contain either percentiles or floats
|
||||||
|
args:
|
||||||
|
str: s
|
||||||
|
returns:
|
||||||
|
float
|
||||||
|
"""
|
||||||
|
if isinstance(s, str) and '%' in s:
|
||||||
|
return float(s.strip('%')) / 100.0
|
||||||
|
return float(s)
|
||||||
|
|
||||||
def permutations_with_replacement(iterable, r=None):
|
def permutations_with_replacement(iterable, r=None):
|
||||||
"""Return successive r length permutations of elements in the iterable.
|
"""Return successive r length permutations of elements in the iterable.
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
a.color {
|
||||||
|
color: rgba(0.0,0.0,0.0,0.5);
|
||||||
|
color: rgba(10.0,10.0,10.0,0.0);
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
a.color {
|
||||||
|
color: hsla(0, 0%, 0%, 0.5);
|
||||||
|
color: hsla(31, 1%, 4%, 0%);
|
||||||
|
}
|
Loading…
Reference in New Issue