diff --git a/src/blinki.py b/src/blinki.py index ef64178..d651762 100644 --- a/src/blinki.py +++ b/src/blinki.py @@ -53,15 +53,37 @@ def morph_grb(grb, steps, mode='single'): raise Exception(f'Mode "{mode}" is not supported.') return grb +def rainbow(device, min_value=1, max_value=255): + """ + Takes an int between 0-255 and either increments or decreases it by the specified steps. + """ + direction = [ + choice([-1, 1]), + choice([-1, 1]), + choice([-1, 1]) + ] + grb = [ + randint(min_value, max_value), + randint(min_value, max_value), + randint(min_value, max_value) + ] + + channel = randint(0, 2) + while True: + #channel = (channel + 1) % 3 + channel = randint(0, 2) + for i in range(30): + candidate = grb[channel] + 1 * direction[channel] + + # if we go out of bounds reverse the direction + if candidate < min_value or candidate > max_value: + direction[channel] = direction[channel] * -1 + else: + grb[channel] = candidate + set_all_leds(device, grb) device = blinkstick.find_first() -# get a random initial color -grb = random_grb() - -while True: - set_all_leds(device, grb) - - grb = morph_grb(grb, 2) +rainbow(device)