mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-15 11:04:55 +00:00
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:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user