示例#1
0
 def __init__(self,
              r: float,
              g: float,
              b: float,
              a: float):
     super().__init__(r, g, b)
     utils.validate(a)
     self._a = a
示例#2
0
文件: views.py 项目: ju-sh/colorviews
 def vals(self, values: Sequence[float]):
     if len(values) != 4:
         raise ValueError("Needs exactly 4 floats")
     utils.validate(values[0])
     utils.validate(values[1])
     utils.validate(values[2])
     utils.validate(values[3])
     self.r, self.g, self.b, self.a = values
示例#3
0
文件: views.py 项目: ju-sh/colorviews
 def vals(self, values: Sequence[float]):
     if len(values) != 4:
         raise ValueError("Needs exactly 4 floats")
     utils.validate(values[0])
     utils.validate(values[1])
     utils.validate(values[2])
     utils.validate(values[3])
     rgb = colorsys.hsv_to_rgb(values[0], values[1], values[2])
     self.color = cast("colors.AlphaColor", self.color)
     self.color.rgba.vals = rgb + (values[3], )
示例#4
0
    def from_name(cls, name: str, a: float = 0.0) -> "AlphaColor":
        """
        Creates an AlphaColor object based on the given color name.

        Only CSS3 extended color keyword names are recognized.

        Arguments:
          name: Name of color.
          a: Alpha value of color as a float in the range [0.0, 1.0].
             Default value is 0.0

        Returns:
          AlphaColor object with value corresponding to the given color name
          and alpha value.
        """
        utils.validate(a)
        a_int = int(a * 0xff)
        name = name.lower()
        rgb_intval = colorviews.names.COLORS[name]
        rgba_intval = (rgb_intval << 8) | a_int
        return cls.from_int(rgba_intval)
示例#5
0
文件: views.py 项目: ju-sh/colorviews
 def vals(self, values: Sequence[float]):
     if len(values) != 3:
         raise ValueError("Needs exactly 3 floats")
     utils.validate(values[0])
     utils.validate(values[1])
     utils.validate(values[2])
     rgb = colorsys.hls_to_rgb(values[0], values[2], values[1])
     self.color = cast("colors.Color", self.color)
     self.color.rgb.vals = rgb
示例#6
0
 def __init__(self,
              r: float,
              g: float,
              b: float):
     utils.validate(r)
     utils.validate(g)
     utils.validate(b)
     self._r = r
     self._g = g
     self._b = b
示例#7
0
    def from_hsva(cls, h: float, s: float, v: float, a: float) -> "AlphaColor":
        """
        Creates an AlphaColor object from the given HSVA float values.

        Arguments:
          h: Hue component of HSVA value as a float in the range [0.0, 1.0]
          s: Saturation component of HSVA value as a float in the
             range [0.0, 1.0].
          v: Value component of HSVA value as a float in the
             range [0.0, 1.0].
          a: Alpha component of HSVA value as a float in the range [0.0, 1.0].

        Returns:
          AlphaColor object with given HSVA values.

        Raises:
          ValueError: If value is outside the valid range.
        """
        utils.validate(h)
        utils.validate(s)
        utils.validate(v)
        utils.validate(a)
        rgba = colorsys.hsv_to_rgb(h, s, v) + (a, )
        return cls(*rgba)
示例#8
0
    def from_hsv(cls, h: float, s: float, v: float) -> "Color":
        """
        Creates a Color object from the given HSV float values.

        Arguments:
          h: Hue component of HSV value as a float in the range [0.0, 1.0]
          s: Saturation component of HSV value as a float in the
             range [0.0, 1.0]
          v: Value component of HSV value as a float in the
             range [0.0, 1.0]

        Returns:
          Color object with given HSV values.

        Raises:
          ValueError: If any argument is outside valid range.
        """
        utils.validate(h)
        utils.validate(s)
        utils.validate(v)
        rgb = colorsys.hsv_to_rgb(h, s, v)
        return cls(*rgb)
示例#9
0
    def from_hsl(cls, h: float, s: float, l: float) -> "Color":
        """
        Creates a Color object from the given HSL float values.

        Arguments:
          h: Hue component of HSL value as a float in the range [0.0, 1.0]
          s: Saturation component of HSL value as a float in the
             range [0.0, 1.0]
          l: Lightness component of HSL value as a float in the
             range [0.0, 1.0]

        Returns:
          Color object with given HSL values.

        Raises:
          ValueError: If any argument is outside valid range.
        """
        utils.validate(h)
        utils.validate(s)
        utils.validate(l)
        rgb = colorsys.hls_to_rgb(h, l, s)
        return cls(*rgb)
示例#10
0
文件: views.py 项目: ju-sh/colorviews
 def b(self, val: float):
     utils.validate(val)
     self.color._b = val
示例#11
0
文件: views.py 项目: ju-sh/colorviews
 def g(self, val: float):
     utils.validate(val)
     self.color._g = val
示例#12
0
 def test_valid(self, val):
     assert validate(val) is None
示例#13
0
文件: views.py 项目: ju-sh/colorviews
 def a(self, val: float):
     utils.validate(val)
     self.color = cast("colors.AlphaColor", self.color)
     self.color._a = val
示例#14
0
文件: views.py 项目: ju-sh/colorviews
 def v(self, val: float):
     utils.validate(val)
     rgb = (self.color._r, self.color._g, self.color._b)
     hsv = colorsys.rgb_to_hsv(*rgb)
     rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], val)
     self.color._r, self.color._g, self.color._b = rgb
示例#15
0
文件: views.py 项目: ju-sh/colorviews
 def l(self, val: float):
     utils.validate(val)
     rgb = (self.color._r, self.color._g, self.color._b)
     hls = colorsys.rgb_to_hls(*rgb)
     rgb = colorsys.hls_to_rgb(hls[0], val, hls[1])
     self.color._r, self.color._g, self.color._b = rgb
示例#16
0
文件: views.py 项目: ju-sh/colorviews
 def r(self, val: float):
     utils.validate(val)
     self.color._r = val
示例#17
0
 def test_invalid(self, val):
     with pytest.raises(ValueError):
         validate(val)