diff options
| -rw-r--r-- | bridge.py | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -1,12 +1,19 @@ -#!/usr/bin/python3 +#!/usr/bin/python """Simple demo of oscillating colors.""" +from __future__ import division import lumiversepython import random import time +FRAME_RATE = 44 +MIN_VALUE = 0 +MAX_VALUE = 1 +MAX_TIME = 4 +MIN_TIME = 0.3 + def get_all_lights(rig): """Return a list of all panels.""" - return [rig.select('$panel={}'.format(i)) for i in range(32)] + return [rig.select('$side={}[$sequence={}]'.format(j, i)) for j in ['top', 'bot'] for i in range(1, 200)] def restrict(low, x, high): @@ -16,7 +23,12 @@ def restrict(low, x, high): def random_change(): """Return a random amount that a light should change each frame.""" - return random.random() / 30 + min_time = int(MIN_TIME * FRAME_RATE) + max_time = int(MAX_TIME * FRAME_RATE) + rands = [random.randint(min_time, max_time) for _ in range(5)] + rand_binom = sum(rands) / 5 + #inverse = (rand_binom - (MAX_VALUE - MIN_VALUE) / 2) % (MAX_VALUE - MIN_VALUE) + MIN_VALUE + return 1 / random.randint(min_time, max_time) def demo(lights, rig): @@ -37,15 +49,23 @@ def demo(lights, rig): light = light_s['light'] current_value = light_s['current_value'] new_value = restrict( - 0, current_value + change * (int(is_increasing) * 2 - 1), 1), 1 + MIN_VALUE, current_value + change * (int(is_increasing) * 2 - 1), MAX_VALUE ) light.setRGBRaw(0, 0, new_value) light_s['current_value'] = new_value - if new_value == 1: + if new_value in [MIN_VALUE, MAX_VALUE]: light_s['is_increasing'] = not is_increasing light_s['change'] = random_change() rig.updateOnce() - time.sleep(1 / 60) + time.sleep(1 / FRAME_RATE) + + +def panels(lights, rig): + for light in lights: + light.setRGBRaw(1, 1, 1) + rig.updateOnce() + time.sleep(1) + light.setRGBRaw(0, 0, 0) def main(): @@ -54,6 +74,7 @@ def main(): rig.init() lights = get_all_lights(rig) demo(lights, rig) + #panels(lights, rig) if __name__ == '__main__': main() |
