|
2 | 2 |
|
3 | 3 |
|
4 | 4 | class ColorableMixin:
|
5 |
| - """Mixin providing color manipulation properties for Light classes.""" |
6 |
| - |
7 |
| - @property |
8 |
| - def red(self) -> int: |
9 |
| - """Red color value.""" |
10 |
| - return getattr(self, "_red", 0) |
11 |
| - |
12 |
| - @red.setter |
13 |
| - def red(self, value: int) -> None: |
14 |
| - self._red = value |
15 |
| - |
16 |
| - @property |
17 |
| - def green(self) -> int: |
18 |
| - """Green color value.""" |
19 |
| - return getattr(self, "_green", 0) |
20 |
| - |
21 |
| - @green.setter |
22 |
| - def green(self, value: int) -> None: |
23 |
| - self._green = value |
24 |
| - |
25 |
| - @property |
26 |
| - def blue(self) -> int: |
27 |
| - """Blue color value.""" |
28 |
| - return getattr(self, "_blue", 0) |
29 |
| - |
30 |
| - @blue.setter |
31 |
| - def blue(self, value: int) -> None: |
32 |
| - self._blue = value |
| 5 | + """Mixin providing color properties.""" |
| 6 | + |
| 7 | + red = property( |
| 8 | + lambda self: getattr(self, "_red", 0), |
| 9 | + lambda self, value: setattr(self, "_red", value), |
| 10 | + doc="Red color value.", |
| 11 | + ) |
| 12 | + |
| 13 | + green = property( |
| 14 | + lambda self: getattr(self, "_green", 0), |
| 15 | + lambda self, value: setattr(self, "_green", value), |
| 16 | + doc="Green color value.", |
| 17 | + ) |
| 18 | + |
| 19 | + blue = property( |
| 20 | + lambda self: getattr(self, "_blue", 0), |
| 21 | + lambda self, value: setattr(self, "_blue", value), |
| 22 | + doc="Blue color value.", |
| 23 | + ) |
33 | 24 |
|
34 | 25 | @property
|
35 | 26 | def color(self) -> tuple[int, int, int]:
|
36 |
| - """A tuple of red, green, and blue color values.""" |
37 |
| - return self.red, self.green, self.blue |
| 27 | + """Tuple of RGB color values.""" |
| 28 | + return (self.red, self.green, self.blue) |
38 | 29 |
|
39 | 30 | @color.setter
|
40 | 31 | def color(self, value: tuple[int, int, int]) -> None:
|
| 32 | + """Tuple of RGB color values.""" |
41 | 33 | self.red, self.green, self.blue = value
|
42 |
| - |
43 |
| - @property |
44 |
| - def is_lit(self) -> bool: |
45 |
| - """True if any color value is greater than 0.""" |
46 |
| - return any(self.color) |
0 commit comments