Skip to content

Commit

Permalink
api/parameters/Color: allow scaling to alter hue
Browse files Browse the repository at this point in the history
This makes it easy for users to vary brightness of the default colors without having to create a whole new object.
  • Loading branch information
laurensvalk committed Aug 26, 2020
1 parent 5e6a8c8 commit 500bac9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pybricks/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def __eq__(self, other):
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')
Expand Down

0 comments on commit 500bac9

Please sign in to comment.