aboutsummaryrefslogtreecommitdiff
path: root/thcolor/_color.py
diff options
context:
space:
mode:
Diffstat (limited to 'thcolor/_color.py')
-rwxr-xr-xthcolor/_color.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/thcolor/_color.py b/thcolor/_color.py
index 76dc505..04dd19f 100755
--- a/thcolor/_color.py
+++ b/thcolor/_color.py
@@ -302,16 +302,12 @@ class Color:
if self._type == Color.Type.RGB:
return (self._r, self._g, self._b)
elif self._type == Color.Type.HSL:
- r, g, b = _hls_to_rgb(self._hue.turns % 1, self._lgt, self._sat)
- r *= 255
- g *= 255
- b *= 255
+ r, g, b = map(lambda x: int(x * 255),
+ _hls_to_rgb(self._hue.turns % 1, self._lgt, self._sat))
return (r, g, b)
elif self._type == Color.Type.HWB:
- r, g, b = _hwb_to_rgb(self._hue.turns % 1, self._wht, self._blk)
- r *= 255
- g *= 255
- b *= 255
+ r, g, b = map(lambda x: int(x * 255),
+ _hwb_to_rgb(self._hue.turns % 1, self._wht, self._blk))
return (r, g, b)
raise ValueError(f"color type {self._type} doesn't translate to rgb")
@@ -333,6 +329,7 @@ class Color:
# notation if the alpha value isn't 1.0.
r, g, b, a = self.rgba()
+ a = round(a, 3)
yield f'#{r:02X}{g:02X}{b:02X}'
if a < 1.0:
@@ -344,11 +341,19 @@ class Color:
if self._type == Type.HSL:
s = round(self._sat, 5) * 100
l = round(self._lgt, 5) * 100
- yield f'hsl({self._hue}, {s}%, {l}%)'
+
+ if a < 1.0:
+ yield f'hsla({self._hue}, {s}%, {l}%, {a})'
+ else:
+ yield f'hsl({self._hue}, {s}%, {l}%)'
elif self._type == Type.HWB:
w = round(self._wht, 5) * 100
b = round(self._blk, 5) * 100
- yield f'hwb({self._hue}, {w}%, {b}%)'
+
+ if a < 1.0:
+ yield f'hwba({self._hue}, {w}%, {b}%, {a})'
+ else:
+ yield f'hwb({self._hue}, {w}%, {b}%)'
return list(statements())