aboutsummaryrefslogtreecommitdiff
path: root/thcolor/_color.py
diff options
context:
space:
mode:
authorThomas Touhey <thomas@touhey.fr>2019-05-10 11:40:49 +0200
committerThomas Touhey <thomas@touhey.fr>2019-05-10 11:40:49 +0200
commitd4c11d05f31c4e28c5af8988cf3e4d2b743de806 (patch)
tree0adf4c1c5b4d8dd9d9ec3fd978744812cd07ea37 /thcolor/_color.py
parenta3a97576e40749ae6ba6cfa1735aa05e63cc2905 (diff)
Corrected formulas, now passes all tests!
Diffstat (limited to 'thcolor/_color.py')
-rwxr-xr-xthcolor/_color.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/thcolor/_color.py b/thcolor/_color.py
index 63b35d5..7850ac4 100755
--- a/thcolor/_color.py
+++ b/thcolor/_color.py
@@ -383,13 +383,9 @@ class Color:
if self._type == Color.Type.RGB:
return (self._r, self._g, self._b)
elif self._type == Color.Type.HSL:
- r, g, b = map(lambda x: int(x * 255),
- _hls_to_rgb(self._hue.turns % 1, self._lgt, self._sat))
- return (r, g, b)
+ return _hls_to_rgb(self._hue, self._lgt, self._sat)
elif self._type == Color.Type.HWB:
- r, g, b = map(lambda x: int(x * 255),
- _hwb_to_rgb(self._hue.turns % 1, self._wht, self._blk))
- return (r, g, b)
+ return _hwb_to_rgb(self._hue, self._wht, self._blk)
raise ValueError(f"color type {self._type} doesn't translate to rgb")
@@ -397,13 +393,11 @@ class Color:
""" Get the (hue, saturation, lightness) components of the color. """
if self._type == Color.Type.RGB:
- h, l, s = _rgb_to_hls(self._r, self._g, self._b)
- return (_Angle(_Angle.Type.TURN, h), s, l)
+ return _rgb_to_hls(self._r, self._g, self._b)
elif self._type == Color.Type.HSL:
return (self._hue, self._sat, self._lgt)
elif self._type == Color.Type.HWB:
- h, l, s = _hwb_to_hls(self._hue.turns % 1, self._wht, self._blk)
- return (_Angle(_Angle.Type.TURN, h), s, l)
+ return _hwb_to_hls(self._hue, self._wht, self._blk)
raise ValueError(f"color type {self._type} doesn't translate to hsl")
@@ -411,11 +405,9 @@ class Color:
""" Get the (hue, whiteness, blackness) components of the color. """
if self._type == Color.Type.RGB:
- h, w, b = _rgb_to_hwb(self._r, self._g, self._b)
- return (_Angle(_Angle.Type.TURN, h), w, b)
+ return _rgb_to_hwb(self._r, self._g, self._b)
elif self._type == Color.Type.HSL:
- h, w, b = _hls_to_hwb(self._hue.turns % 1, self._lgt, self._sat)
- return (_Angle(_Angle.Type.TURN, h), w, b)
+ return _hls_to_hwb(self._hue, self._lgt, self._sat)
elif self._type == Color.Type.HWB:
return (self._hue, self._wht, self._blk)
@@ -448,6 +440,14 @@ class Color:
h, s, l, a = self.hsla()
return (h, l, s, a)
+ def hwba(self):
+ """ Get the (hue, whiteness, blackness, alpha) components of
+ the color. """
+
+ h, w, b = self.hwb()
+ a = self._alpha
+ return (h, w, b, a)
+
def css(self):
""" Get the CSS declarations (with compatibility management). """
@@ -471,17 +471,17 @@ class Color:
l = round(self._lgt, 5) * 100
if a < 1.0:
- yield f'hsla({self._hue}, {s}%, {l}%, {a})'
+ yield f'hsla({self._hue.degrees}deg, {s}%, {l}%, {a})'
else:
- yield f'hsl({self._hue}, {s}%, {l}%)'
+ yield f'hsl({self._hue.degrees}deg, {s}%, {l}%)'
elif self._type == Type.HWB:
w = round(self._wht, 5) * 100
b = round(self._blk, 5) * 100
if a < 1.0:
- yield f'hwba({self._hue}, {w}%, {b}%, {a})'
+ yield f'hwba({self._hue.degrees}deg, {w}%, {b}%, {a})'
else:
- yield f'hwb({self._hue}, {w}%, {b}%)'
+ yield f'hwb({self._hue.degrees}deg, {w}%, {b}%)'
return list(statements())