Skip to content

Commit

Permalink
Added wrap_around option for pixel.decrement()
Browse files Browse the repository at this point in the history
  • Loading branch information
speratus committed Oct 31, 2019
1 parent 0bfa94d commit 6dc78c6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions blinkter/pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def increment(self, led: LED, amount=0, wrap_around=False):
## self.rgb[led] = c
self.draw()

def decrement(self, led: LED, amount=0):
def decrement(self, led: LED, amount=0, wrap_around=False):
"""
Decreases the brightness of the specified LED by the specified amount.
Expand All @@ -176,13 +176,17 @@ def decrement(self, led: LED, amount=0):
self._keep_color()

a = amount if amount is not 0 else self.increment_amount

too_lo = 255 if wrap_around is True else 0
too_hi = 0 if wrap_around is True else 255

#print(f'using value {a}')
c = self.rgb[led.value]
if c-a < 0:
c = 0
c = too_lo
self.rgb[led.value] = c
elif c-a > 255:
c = 255
c = too_hi
self.rgb[led.value] = c
else:
c -= a
Expand Down

0 comments on commit 6dc78c6

Please sign in to comment.