Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @dataclass
- class RGB:
- r: int
- g: int
- b: int
- def _op(self, other, op):
- return RGB(*(op(s, o) for s, o in zip(self, other)))
- def __sub__(self, other):
- return self._op(other, operator.sub)
- def __add__(self, other):
- return self._op(other, operator.add)
- def __div__(self, other):
- return self._op(other, operator.div)
- def __truediv__(self, other):
- if isinstance(other, int):
- return RGB(*(s / other for s in self))
- return self._op(other, operator.truediv)
- def __iter__(self):
- yield from (self.r, self.g, self.b)
- @property
- def int(self):
- return RGB(*(abs(round(x)) for x in self))
- @property
- def tuple(self):
- return tuple(self)
- def gen_colors(src, dst, count):
- src, dst = RGB(*src), RGB(*dst)
- delta = dst - src
- step = delta / (count - 1)
- yield src.int.tuple
- for idx in range(count - 1):
- src += step
- yield src.int.tuple
- red = (255, 0, 0)
- blue = (0, 0, 255)
- colors = list(gen_colors(red, blue, 72))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement