api/parameters/Color: allow scaling to alter hue

This makes it easy for users to vary brightness of the default colors without having to create a whole new object.
This commit is contained in:
Laurens Valk
2020-08-26 21:12:48 +02:00
parent 5e6a8c8334
commit 500bac9929
+7
View File
@@ -45,6 +45,13 @@ class Color:
return (isinstance(other, Color) and
self.h == other.h and self.s == other.s and self.v == other.v)
def __mul__(self, scale):
v = max(0, min(self.v * scale, 100))
return Color(self.h, self.s, int(v), self.name)
def __rmul__(self, scale):
return self.__mul__(scale)
Color.BLACK = Color(0, 0, 0, 'BLACK')
Color.GRAY = Color(0, 0, 50, 'GRAY')