diff options
| author | Raymond Hogenson <rayhogenson@openmailbox.org> | 2016-09-27 22:58:31 -0400 |
|---|---|---|
| committer | Raymond Hogenson <rayhogenson@openmailbox.org> | 2016-09-27 22:58:31 -0400 |
| commit | fea99295c9ca99d3f3abd41b9bfaac91f4bda6dd (patch) | |
| tree | bf8c763b9cda0cf985614048758c35398b184126 /bridge.py | |
| parent | 78fde3bb014ecd8e2368f2cc088839aecd0ca1ed (diff) | |
| download | bridge-fea99295c9ca99d3f3abd41b9bfaac91f4bda6dd.tar.zst | |
Split files and finish render code
Although it is unlikely that this code will actually run, it is split up
rather nicely such that it should be maintainable into the future.
Right now only one fish is supported, and it moves at some fixed rate
across the bridge. This is fine for a demo, but the rendering process
will need to be changed significantly before the end.
Diffstat (limited to 'bridge.py')
| -rw-r--r-- | bridge.py | 69 |
1 files changed, 11 insertions, 58 deletions
@@ -1,76 +1,29 @@ #!/usr/bin/python """Simple demo of oscillating colors.""" -from __future__ import division +from __future__ import division, unicode_literals import color -import colorsys +import constants +import fish_render import lumiversepython -import math -import random import time -FRAME_RATE = 44 -MIN_VALUE = 0 -MAX_VALUE = 1 -MAX_TIME = 4 -MIN_TIME = 0.3 -MAX_HUE = 169 / 360 -MIN_HUE = 250 / 360 - def get_all_lights(rig): """Return a list of all panels.""" return [ - rig.select('$side={}[$sequence={}]'.format(j, i)) - for j in ['top', 'bot'] for i in range(1, 200) + [ + rig.select('$side={y}[$sequence={x}]'.format({'y': y, 'x': x})) + for y in ('top', 'bot') + ] for x in xrange(1, 200) ] -def pick_HSV(): - """Return a random color in an appropriate interval.""" - hue = random.random() * (MAX_HUE - MIN_HUE) + MIN_HUE - saturation = random.random() - value = random.random() - return color.HSV(hue, saturation, value) - - -def transition(start, end, step): - """Return a vector equal to (end - start) * step + start.""" - return (end - start) / abs(end - start) * step + start - - -def random_change(): - """Return a random amount that a light should change each frame.""" - min_time = int(MIN_TIME * FRAME_RATE) - max_time = int(MAX_TIME * FRAME_RATE) - return 1 / random.randint(min_time, max_time) - - def demo(lights, rig): """Do some light things.""" - light_status = [ - { - 'change': 0, - 'light': light, - 'current value': color.RGB(0, 0, 0), - 'transitioning to': color.RGB(0, 0, 0), - } - for light in lights - ] + fish = fish_render.Fish(0, 0, 2, 1, color.red, 1 / constants.FRAME_RATE) + bridge = fish_render.Bridge(lights, fish, rig) while True: - for light_s in light_status: - change = light_s['change'] - light = light_s['light'] - current_value = light_s['current value'] - transitioning_to = light_s['transitioning to'] - if abs(transitioning_to - current_value) < change: - change = random_change() - light_s['change'] = change - transitioning_to = pick_HSV().to_RGB() - light_s['transitioning to'] = transitioning_to - new_color = transition(current_value, transitioning_to, change) - light.setRGBRaw(*new_color.components) - light_s['current value'] = new_color - rig.updateOnce() - time.sleep(1 / FRAME_RATE) + bridge.update() + time.sleep(1 / constants.FRAME_RATE) def main(): |
