aboutsummaryrefslogtreecommitdiff
path: root/thcolor/colors.py
diff options
context:
space:
mode:
Diffstat (limited to 'thcolor/colors.py')
-rw-r--r--thcolor/colors.py343
1 files changed, 167 insertions, 176 deletions
diff --git a/thcolor/colors.py b/thcolor/colors.py
index 2be1985..cfc9240 100644
--- a/thcolor/colors.py
+++ b/thcolor/colors.py
@@ -3,7 +3,7 @@
# Copyright (C) 2019-2022 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
# This file is part of the thcolor project, which is MIT-licensed.
# *****************************************************************************
-""" Color representations and conversions. """
+"""Color representations and conversions."""
from math import (
atan2 as _atan2, ceil as _ceil, cos as _cos, sin as _sin, sqrt as _sqrt,
@@ -26,9 +26,9 @@ __all__ = [
class Color:
- """ Class representing a color within thcolor.
+ """Class representing a color within thcolor.
- :param alpha: Value for :py:attr:`alpha`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_alpha')
@@ -68,10 +68,10 @@ class Color:
@property
def alpha(self) -> float:
- """ The alpha component value.
+ """Get the alpha component value.
- Represented as a float varying between 0.0 (invisible)
- and 1.0 (opaque).
+ Represented as a float varying between 0.0 (invisible)
+ and 1.0 (opaque).
"""
return self._alpha
@@ -82,9 +82,9 @@ class Color:
expr: str,
decoder: _Optional[_Any] = None,
) -> 'Color':
- """ Create a color from a string.
+ """Create a color from a string.
- :param expr: The expression to decode.
+ :param expr: The expression to decode.
"""
if decoder is None:
@@ -107,52 +107,52 @@ class Color:
# ---
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
raise NotImplementedError
def ashsl(self) -> 'HSLColor':
- """ Get an HSLColor out of the current object. """
+ """Get an HSLColor out of the current object."""
return self.assrgb().ashsl()
def ashsv(self) -> 'HSVColor':
- """ Get an HSVColor out of the current object. """
+ """Get an HSVColor out of the current object."""
return self.assrgb().ashsv()
def ashwb(self) -> 'HWBColor':
- """ Get an HWBColor out of the current object. """
+ """Get an HWBColor out of the current object."""
return self.assrgb().ashwb()
def ascmyk(self) -> 'CMYKColor':
- """ Get a CMYKColor out of the current object. """
+ """Get a CMYKColor out of the current object."""
return self.assrgb().ascmyk()
def aslab(self) -> 'LABColor':
- """ Get a LABColor out of the current object. """
+ """Get a LABColor out of the current object."""
raise NotImplementedError
def aslch(self) -> 'LCHColor':
- """ Get a LCHColor out of the current object. """
+ """Get a LCHColor out of the current object."""
raise NotImplementedError
def asxyz(self) -> 'XYZColor':
- """ Get an XYZColor out of the current object. """
+ """Get an XYZColor out of the current object."""
raise NotImplementedError
def asyiq(self) -> 'YIQColor':
- """ Get an YIQColor out of the current object. """
+ """Get an YIQColor out of the current object."""
return self.assrgb().asyiq()
def asyuv(self) -> 'YUVColor':
- """ Get an YUVColor out of the current object. """
+ """Get an YUVColor out of the current object."""
return self.assrgb().asyuv()
@@ -161,25 +161,24 @@ class Color:
# ---
def replace(self, **properties) -> 'Color':
- """ Get the color with the given properties replaced.
+ """Get the color with the given properties replaced.
- For changing the alpha on an RGB color:
+ For changing the alpha on an RGB color:
- .. code-block:: python
+ .. code-block:: python
- >>> SRGBColor(.1, .2, .3).replace(alpha=.5)
- ... SRGBColor(red=0.1, green=0.2, blue=0.3, alpha=0.5)
+ >>> SRGBColor(.1, .2, .3).replace(alpha=.5)
+ ... SRGBColor(red=0.1, green=0.2, blue=0.3, alpha=0.5)
- For changing the lightness on an HSL color:
+ For changing the lightness on an HSL color:
- .. code-block:: pycon
+ .. code-block:: pycon
- >>> HSLColor(DegreesAngle(270), .5, 1).replace(lightness=.2)
- ... HSLColor(hue=DegreesAngle(degrees=270.0), saturation=0.5,
- ... lightness=0.2, alpha=1.0)
+ >>> HSLColor(DegreesAngle(270), .5, 1).replace(lightness=.2)
+ ... HSLColor(hue=DegreesAngle(degrees=270.0), saturation=0.5,
+ ... lightness=0.2, alpha=1.0)
- :param properties: Properties to change from the original
- color.
+ :param properties: Properties to change from the original color.
"""
params = {
@@ -199,53 +198,53 @@ class Color:
return type(self)(**params)
def darker(self, by: float = 0.1) -> 'Color':
- """ Get a darker version of the given color.
+ """Get a darker version of the given color.
- :param by: Percentage by which the color should be darker.
+ :param by: Percentage by which the color should be darker.
"""
color = self.ashsl()
return color.replace(lightness=max(color.lightness - by, 0.0))
def lighter(self, by: float = 0.1) -> 'Color':
- """ Get a lighter version of the given color.
+ """Get a lighter version of the given color.
- :param by: Percentage by which the color should be lighter.
+ :param by: Percentage by which the color should be lighter.
"""
color = self.ashsl()
return color.replace(lightness=min(color.lightness + by, 1.0))
def desaturate(self, by: float = 0.1) -> 'Color':
- """ Get a less saturated version of the given color.
+ """Get a less saturated version of the given color.
- :param by: Percentage by which the color should be
- desaturated.
+ :param by: Percentage by which the color should be
+ desaturated.
"""
color = self.ashsl()
return color.replace(saturation=max(color.saturation - by, 0.0))
def saturate(self, by: float = 0.1) -> 'Color':
- """ Get a more saturated version of the given color.
+ """Get a more saturated version of the given color.
- :param by: Percentage by which the color should be
- saturated.
+ :param by: Percentage by which the color should be
+ saturated.
"""
color = self.ashsl()
return color.replace(saturation=min(color.saturation + by, 1.0))
def css(self) -> _Sequence[str]:
- """ Get the CSS color descriptions.
+ """Get the CSS color descriptions.
- Includes older CSS specifications compatibility,
- as a sequence of strings.
+ Includes older CSS specifications compatibility,
+ as a sequence of strings.
- For example:
+ For example:
- >>> SRGBColor.frombytes(18, 52, 86, 0.82).css()
- ... ("#123456", "rgba(18, 52, 86, 82%)")
+ >>> SRGBColor.frombytes(18, 52, 86, 0.82).css()
+ ... ("#123456", "rgba(18, 52, 86, 82%)")
"""
def _percent(prop):
@@ -261,7 +260,6 @@ class Color:
# Start by yelling a #RRGGBB color, compatible with most
# web browsers around the world, followed by the rgba()
# notation if the alpha value isn't 1.0.
-
a = _round_half_up(self.alpha, 3)
try:
@@ -278,7 +276,6 @@ class Color:
# Then yield more specific CSS declarations in case
# they're supported (which would be neat!).
-
if isinstance(self, HSLColor):
hue, sat, lgt = (
self.hue, self.saturation, self.lightness,
@@ -311,12 +308,12 @@ class Color:
class SRGBColor(Color):
- """ A color expressed using its channel intensities in the sRGB profile.
+ """A color expressed using its channel intensities in the sRGB profile.
- :param red: Value for :py:attr:`red`.
- :param green: Value for :py:attr:`green`.
- :param blue: Value for :py:attr:`blue`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param red: Value for :py:attr:`red`.
+ :param green: Value for :py:attr:`green`.
+ :param blue: Value for :py:attr:`blue`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_red', '_green', '_blue')
@@ -360,27 +357,27 @@ class SRGBColor(Color):
@property
def red(self) -> float:
- """ The intensity of the red channel.
+ """Get the intensity of the red channel.
- Represented as a float between 0.0 (dark) and 1.0 (light).
+ Represented as a float between 0.0 (dark) and 1.0 (light).
"""
return self._red
@property
def green(self) -> float:
- """ The intensity of the green channel.
+ """Get the intensity of the green channel.
- Represented as a float between 0.0 (dark) and 1.0 (light).
+ Represented as a float between 0.0 (dark) and 1.0 (light).
"""
return self._green
@property
def blue(self) -> float:
- """ The intensity of the blue channel.
+ """Get the intensity of the blue channel.
- Represented as a float between 0.0 (dark) and 1.0 (light).
+ Represented as a float between 0.0 (dark) and 1.0 (light).
"""
return self._blue
@@ -393,7 +390,7 @@ class SRGBColor(Color):
blue: int,
alpha: float = 1.0,
) -> 'SRGBColor':
- """ Get an sRGB color from colors using values between 0 and 255. """
+ """Get an sRGB color from colors using values between 0 and 255."""
return cls(
red=red / 255,
@@ -404,7 +401,7 @@ class SRGBColor(Color):
@classmethod
def fromnetscapecolorname(cls, name: str) -> 'SRGBColor':
- """ Get an sRGB color from a Netscape color name. """
+ """Get an sRGB color from a Netscape color name."""
name = str(name)
if name[0] == '#':
@@ -417,7 +414,6 @@ class SRGBColor(Color):
# by '0' characters (the 0xFFFF limit is due to how
# UTF-16 was managed at the time).
# - we truncate our input to 128 characters.
-
name = name.lower()
name = ''.join(
c if c in '0123456789abcdef' else '00'[:1 + (ord(c) > 0xFFFF)]
@@ -429,7 +425,6 @@ class SRGBColor(Color):
# `sz` is the size of the digits slice to take in that zone
# (max. 8).
# `of` is the offset in the zone of the slice to take.
-
iv = _ceil(len(name) / 3)
of = iv - 8 if iv > 8 else 0
sz = iv - of
@@ -437,7 +432,6 @@ class SRGBColor(Color):
# Then we isolate the slices using the values calculated
# above. `gr` will be an array of 3 or 4 digit strings
# (depending on the number of members).
-
gr = list(map(
lambda i: name[i * iv + of:i * iv + iv].ljust(sz, '0'),
range(3),
@@ -445,18 +439,16 @@ class SRGBColor(Color):
# Check how many digits we can skip at the beginning of
# each slice.
-
pre = min(map(lambda x: len(x) - len(x.lstrip('0')), gr))
pre = min(pre, sz - 2)
# Then we extract the values.
-
r, g, b = map(lambda x: int('0' + x[pre:pre + 2], 16), gr)
return cls.frombytes(r, g, b)
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
return SRGBColor(
red=self.red,
@@ -466,7 +458,7 @@ class SRGBColor(Color):
)
def ashsl(self) -> 'HSLColor':
- """ Get an HSLColor out of the current object. """
+ """Get an HSLColor out of the current object."""
r, g, b = self.red, self.green, self.blue
@@ -502,7 +494,7 @@ class SRGBColor(Color):
)
def ashsv(self) -> 'HSVColor':
- """ Get an HSVColor out of the current object. """
+ """Get an HSVColor out of the current object."""
r, g, b = self.red, self.green, self.blue
maxc = max(r, g, b)
@@ -532,7 +524,7 @@ class SRGBColor(Color):
)
def ashwb(self) -> 'HWBColor':
- """ Get an HWBColor out of the current object. """
+ """Get an HWBColor out of the current object."""
r, g, b = self.red, self.green, self.blue
@@ -541,7 +533,7 @@ class SRGBColor(Color):
chroma = max_ - min_
if chroma == 0:
- hue = 0
+ hue = 0.
elif r == max_:
hue = (g - b) / chroma
elif g == max_:
@@ -561,7 +553,7 @@ class SRGBColor(Color):
)
def ascmyk(self) -> 'CMYKColor':
- """ Get a CMYKColor out of the current object. """
+ """Get a CMYKColor out of the current object."""
r, g, b, _ = self
@@ -582,7 +574,7 @@ class SRGBColor(Color):
)
def asyiq(self) -> 'YIQColor':
- """ Get an YIQColor out of the current object. """
+ """Get an YIQColor out of the current object."""
r, g, b = self.red, self.green, self.blue
@@ -594,7 +586,7 @@ class SRGBColor(Color):
)
def asbytes(self) -> _Tuple[int, int, int]:
- """ Get the red, blue and green bytes. """
+ """Get the red, blue and green bytes."""
return (
int(_round_half_up(self.red * 255)),
@@ -604,12 +596,12 @@ class SRGBColor(Color):
class HSLColor(Color):
- """ A color expressed using its hue, saturation and lightness components.
+ """A color expressed using its hue, saturation and lightness components.
- :param hue: Value for :py:attr:`hue`.
- :param saturation: Value for :py:attr:`saturation`.
- :param lightness: Value for :py:attr:`lightness`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param hue: Value for :py:attr:`hue`.
+ :param saturation: Value for :py:attr:`saturation`.
+ :param lightness: Value for :py:attr:`lightness`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_hue', '_saturation', '_lightness')
@@ -654,26 +646,26 @@ class HSLColor(Color):
@property
def hue(self) -> _Angle:
- """ The hue, as an angle. """
+ """Get the hue, as an angle."""
return self._hue
@property
def saturation(self) -> float:
- """ The saturation, between 0.0 and 1.0. """
+ """Get the saturation, between 0.0 and 1.0."""
return self._saturation
@property
def lightness(self) -> float:
- """ The lightness, between 0.0 and 1.0. """
+ """Get the lightness, between 0.0 and 1.0."""
return self._lightness
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
- hue, s, lgt = self.hue.asdegrees(), self.saturation, self.lightness
+ hue_obj, s, lgt = self.hue.asdegrees(), self.saturation, self.lightness
if s == 0:
# Achromatic color.
@@ -696,7 +688,7 @@ class HSLColor(Color):
return t1 + (t2 - t1) * (4 - hue)
return t1
- hue = (hue.degrees % 360) / 60
+ hue = (hue_obj.degrees % 360) / 60
if lgt <= 0.5:
t2 = lgt * (s + 1)
else:
@@ -712,7 +704,7 @@ class HSLColor(Color):
)
def ashsl(self) -> 'HSLColor':
- """ Get an HSLColor out of the current object. """
+ """Get an HSLColor out of the current object."""
return HSLColor(
hue=self.hue,
@@ -723,12 +715,12 @@ class HSLColor(Color):
class HSVColor(Color):
- """ A color expressed using its hue, saturation and value components.
+ """A color expressed using its hue, saturation and value components.
- :param hue: Value for :py:attr:`hue`.
- :param saturation: Value for :py:attr:`saturation`.
- :param value: Value for :py:attr:`value`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param hue: Value for :py:attr:`hue`.
+ :param saturation: Value for :py:attr:`saturation`.
+ :param value: Value for :py:attr:`value`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_hue', '_saturation', '_value')
@@ -752,24 +744,24 @@ class HSVColor(Color):
@property
def hue(self) -> _Angle:
- """ The hue, as an angle. """
+ """Get the hue, as an angle."""
return self._hue
@property
def saturation(self) -> float:
- """ The saturation, between 0.0 and 1.0. """
+ """Get the saturation, between 0.0 and 1.0."""
return self._saturation
@property
def value(self) -> float:
- """ The value, between 0.0 and 1.0. """
+ """Get the value, between 0.0 and 1.0."""
return self._value
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
hue, saturation, value = (
self.hue.asturns(),
@@ -808,7 +800,7 @@ class HSVColor(Color):
)
def ashsv(self) -> 'HSVColor':
- """ Get an HSVColor out of the current object. """
+ """Get an HSVColor out of the current object."""
return HSVColor(
hue=self.hue,
@@ -819,12 +811,12 @@ class HSVColor(Color):
class HWBColor(Color):
- """ A color expressed using its hue, whiteness and blackness components.
+ """A color expressed using its hue, whiteness and blackness components.
- :param hue: Value for :py:attr:`hue`.
- :param whiteness: Value for :py:attr:`whiteness`.
- :param blackness: Value for :py:attr:`blackness`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param hue: Value for :py:attr:`hue`.
+ :param whiteness: Value for :py:attr:`whiteness`.
+ :param blackness: Value for :py:attr:`blackness`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_hue', '_whiteness', '_blackness')
@@ -848,24 +840,24 @@ class HWBColor(Color):
@property
def hue(self) -> _Angle:
- """ The hue, as an angle. """
+ """Get the hue, as an angle."""
return self._hue
@property
def whiteness(self) -> float:
- """ The whiteness, as a value between 0.0 and 1.0. """
+ """Get the whiteness, as a value between 0.0 and 1.0."""
return self._whiteness
@property
def blackness(self) -> float:
- """ The blackness, as a value between 0.0 and 1.0. """
+ """Get the blackness, as a value between 0.0 and 1.0."""
return self._blackness
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
hue, w, bl = self.hue, self.whiteness, self.blackness
@@ -885,7 +877,7 @@ class HWBColor(Color):
)
def ashwb(self) -> 'HWBColor':
- """ Get an HWBColor out of the current object. """
+ """Get an HWBColor out of the current object."""
return HWBColor(
hue=self.hue,
@@ -896,13 +888,13 @@ class HWBColor(Color):
class CMYKColor(Color):
- """ A color expressed using its CMYK channels' intensities.
+ """A color expressed using its CMYK channels' intensities.
- :param cyan: Value for :py:attr:`cyan`.
- :param magenta: Value for :py:attr:`magenta`.
- :param yellow: Value for :py:attr:`yellow`.
- :param black: Value for :py:attr:`black`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param cyan: Value for :py:attr:`cyan`.
+ :param magenta: Value for :py:attr:`magenta`.
+ :param yellow: Value for :py:attr:`yellow`.
+ :param black: Value for :py:attr:`black`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_cyan', '_magenta', '_yellow', '_black')
@@ -934,30 +926,30 @@ class CMYKColor(Color):
@property
def cyan(self):
- """ Cyan channel intensity between 0.0 and 1.0. """
+ """Get the cyan channel intensity between 0.0 and 1.0."""
return self._cyan
@property
def magenta(self):
- """ Magenta channel intensity between 0.0 and 1.0. """
+ """Get the magenta channel intensity between 0.0 and 1.0."""
return self._magenta
@property
def yellow(self):
- """ Yellow channel intensity between 0.0 and 1.0. """
+ """Get the yellow channel intensity between 0.0 and 1.0."""
return self._yellow
@property
def black(self):
- """ Black channel intensity between 0.0 and 1.0. """
+ """Get the black channel intensity between 0.0 and 1.0."""
return self._black
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
c, m, y, k = self.cyan, self.magenta, self.yellow, self.black
@@ -973,7 +965,7 @@ class CMYKColor(Color):
)
def ascmyk(self) -> 'CMYKColor':
- """ Get a CMYKColor out of the current object. """
+ """Get a CMYKColor out of the current object."""
return CMYKColor(
cyan=self.cyan,
@@ -985,12 +977,12 @@ class CMYKColor(Color):
class LABColor(Color):
- """ A color expressed using its CIELAB color space cartesian coordinates.
+ """A color expressed using its CIELAB color space cartesian coordinates.
- :param lightness: Value for :py:attr:`lightness`.
- :param a: Value for :py:attr:`a`.
- :param b: Value for :py:attr:`b`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param lightness: Value for :py:attr:`lightness`.
+ :param a: Value for :py:attr:`a`.
+ :param b: Value for :py:attr:`b`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_lightness', '_a', '_b')
@@ -1014,33 +1006,33 @@ class LABColor(Color):
@property
def lightness(self) -> float:
- """ The CIE lightness.
+ """Get the CIE lightness.
- Similar to the lightness in the HSL representation.
- Represented as a float between 0.0 and 1.0.
+ Similar to the lightness in the HSL representation.
+ Represented as a float between 0.0 and 1.0.
"""
return self._lightness
@property
def a(self) -> float:
- """ The A axis value in the Lab colorspace. """
+ """Get the A axis value in the Lab colorspace."""
return self._a
@property
def b(self) -> float:
- """ The B axis value in the Lab colorspace. """
+ """Get the B axis value in the Lab colorspace."""
return self._b
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
return self.asxyz().assrgb()
def aslab(self) -> 'LABColor':
- """ Get a LABColor out of the current object. """
+ """Get a LABColor out of the current object."""
return LABColor(
lightness=self.lightness,
@@ -1050,7 +1042,7 @@ class LABColor(Color):
)
def aslch(self) -> 'LCHColor':
- """ Get a LCHColor out of the current object. """
+ """Get a LCHColor out of the current object."""
l, a, b = self.lightness, self.a, self.b
@@ -1063,12 +1055,12 @@ class LABColor(Color):
class LCHColor(Color):
- """ A color expressed using its CIELAB color space polar coordinates.
+ """A color expressed using its CIELAB color space polar coordinates.
- :param lightness: Value for :py:attr:`lightness`.
- :param chroma: Value for :py:attr:`chroma`.
- :param hue: Value for :py:attr:`hue`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param lightness: Value for :py:attr:`lightness`.
+ :param chroma: Value for :py:attr:`chroma`.
+ :param hue: Value for :py:attr:`hue`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_lightness', '_chroma', '_hue', '_alpha')
@@ -1111,36 +1103,36 @@ class LCHColor(Color):
@property
def lightness(self) -> float:
- """ The CIE lightness.
+ """Get the CIE lightness.
- Similar to the lightness in the HSL representation.
- Represented as a float between 0.0 and 1.0.
+ Similar to the lightness in the HSL representation.
+ Represented as a float between 0.0 and 1.0.
"""
return self._lightness
@property
def chroma(self) -> float:
- """ The chroma.
+ """Get the chroma.
- Represented as a positive number theoretically unbounded.
+ Represented as a positive number theoretically unbounded.
"""
return self._chroma
@property
def hue(self) -> _Angle:
- """ The hue, as an angle. """
+ """Get the hue, as an angle."""
return self._hue
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
return self.aslab().asxyz().assrgb()
def aslab(self) -> 'LABColor':
- """ Get a LABColor out of the current object. """
+ """Get a LABColor out of the current object."""
l, c, h = self.lightness, self.chroma, self.hue.asradians()
@@ -1152,7 +1144,7 @@ class LCHColor(Color):
)
def aslch(self) -> 'LCHColor':
- """ Get a LCHColor out of the current object. """
+ """Get a LCHColor out of the current object."""
return LCHColor(
lightness=self.lightness,
@@ -1163,12 +1155,12 @@ class LCHColor(Color):
class XYZColor(Color):
- """ A color expressed using its CIEXYZ color space coordinates.
+ """A color expressed using its CIEXYZ color space coordinates.
- :param x: Value for :py:attr:`x`.
- :param y: Value for :py:attr:`y`.
- :param z: Value for :py:attr:`z`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param x: Value for :py:attr:`x`.
+ :param y: Value for :py:attr:`y`.
+ :param z: Value for :py:attr:`z`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_x', '_y', '_z')
@@ -1210,24 +1202,24 @@ class XYZColor(Color):
@property
def x(self) -> float:
- """ The CIE X component, between 0.0 and 1.0. """
+ """Get the CIE X component, between 0.0 and 1.0."""
return self._x
@property
def y(self) -> float:
- """ The CIE Y component, between 0.0 and 1.0. """
+ """Get the CIE Y component, between 0.0 and 1.0."""
return self._y
@property
def z(self) -> float:
- """ The CIE Z component, between 0.0 and 1.0. """
+ """Get the CIE Z component, between 0.0 and 1.0."""
return self._z
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
# For more information about this algorithm, see these links:
#
@@ -1258,7 +1250,7 @@ class XYZColor(Color):
)
def aslab(self) -> 'LABColor':
- """ Get a LABColor out of the current object. """
+ """Get a LABColor out of the current object."""
x, y, z = self.x, self.y, self.z
@@ -1288,7 +1280,7 @@ class XYZColor(Color):
)
def asxyz(self) -> 'XYZColor':
- """ Get an XYZColor out of the current object. """
+ """Get an XYZColor out of the current object."""
return XYZColor(
x=self.x,
@@ -1299,12 +1291,12 @@ class XYZColor(Color):
class YIQColor(Color):
- """ A color expressed using its YIQ components.
+ """A color expressed using its YIQ components.
- :param y: Value for :py:attr:`y`.
- :param i: Value for :py:attr:`i`.
- :param q: Value for :py:attr:`q`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param y: Value for :py:attr:`y`.
+ :param i: Value for :py:attr:`i`.
+ :param q: Value for :py:attr:`q`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_y', '_i', '_q')
@@ -1328,24 +1320,24 @@ class YIQColor(Color):
@property
def y(self) -> float:
- """ The luma. """
+ """Get the luma."""
return self._y
@property
def i(self) -> float:
- """ The orange-blue range value. """
+ """Get the orange-blue range value."""
return self._i
@property
def q(self) -> float:
- """ The purple-green range value. """
+ """Get the purple-green range value."""
return self._q
def assrgb(self) -> 'SRGBColor':
- """ Get an SRGBColor out of the current object. """
+ """Get an SRGBColor out of the current object."""
y, i, q = self.y, self.i, self.q
@@ -1363,7 +1355,7 @@ class YIQColor(Color):
)
def asyiq(self) -> 'YIQColor':
- """ Get an YIQColor out of the current object. """
+ """Get an YIQColor out of the current object."""
return YIQColor(
y=self.y,
@@ -1374,12 +1366,12 @@ class YIQColor(Color):
class YUVColor(Color):
- """ A color expressed using its YUV components.
+ """A color expressed using its YUV components.
- :param y: Value for :py:attr:`y`.
- :param u: Value for :py:attr:`u`.
- :param v: Value for :py:attr:`v`.
- :param alpha: Value for :py:attr:`alpha`.
+ :param y: Value for :py:attr:`y`.
+ :param u: Value for :py:attr:`u`.
+ :param v: Value for :py:attr:`v`.
+ :param alpha: Value for :py:attr:`alpha`.
"""
__slots__ = ('_y', '_u', '_v')
@@ -1403,24 +1395,24 @@ class YUVColor(Color):
@property
def y(self) -> float:
- """ The luma. """
+ """Get the luma."""
return self._y
@property
def u(self) -> float:
- """ The U chrominance. """
+ """Get the U chrominance."""
return self._u
@property
def v(self) -> float:
- """ The V chrominance. """
+ """Get the V chrominance."""
return self._v
def asyuv(self) -> 'YUVColor':
- """ Get an YUVColor out of the current object. """
+ """Get an YUVColor out of the current object."""
return YUVColor(
y=self.y,
@@ -1429,5 +1421,4 @@ class YUVColor(Color):
alpha=self.alpha,
)
-
# End of file.