summaryrefslogtreecommitdiffstats
path: root/bridge.py
diff options
context:
space:
mode:
authorAaron Perley <aaron.perley@gmail.com>2016-10-09 18:00:10 -0400
committerAaron Perley <aaron.perley@gmail.com>2016-10-09 18:00:10 -0400
commitf05ccbe166fd2501be3502f81f0562e73291fa04 (patch)
treecbc4eb9b8de594533e4f8b262385652b0dfd0309 /bridge.py
parentf0cb39571e4ac16b6fab6b04c26e17897e61f9f5 (diff)
downloadbridge-f05ccbe166fd2501be3502f81f0562e73291fa04.tar.zst
Refactor bridge, fish show, and sunrise show code
Diffstat (limited to 'bridge.py')
-rw-r--r--[-rwxr-xr-x]bridge.py79
1 files changed, 27 insertions, 52 deletions
diff --git a/bridge.py b/bridge.py
index 4d5d817..70adb99 100755..100644
--- a/bridge.py
+++ b/bridge.py
@@ -1,12 +1,7 @@
-#!/usr/bin/python2
-"""Simple demo of oscillating colors."""
-from __future__ import division, print_function
-import color
-import constants
-import fish_render
-import sunrise
-import time
-import random
+from fish_show import FishShow
+from sunrise import SunriseShow
+from constants import *
+
try:
import lumiversepython
except ImportError:
@@ -15,55 +10,35 @@ except ImportError:
else:
have_lumiversepython = True
+class Bridge(object):
+ WIDTH = 200
+ HEIGHT = 2
+ def __init__(self):
+ if have_lumiversepython:
+ self.rig = lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
+ else:
+ self.rig = DummyRig(self.WIDTH, self.HEIGHT)
+ self.rig.init()
+ self.lights = self.get_lights()
+ def update(self):
+ self.rig.updateOnce()
-#fish_render = sunrise
-
-
-
-
-
-
-def get_all_lights(rig):
- """Return a list of all panels."""
- return [
- [
- fish_render.Light(
- x, int(y == 'top'),
- rig.select('$side={y}[$sequence={x}]'.format(y=y, x=x))
- ) for y in ('top', 'bot')
- ] for x in xrange(1, 200)
- ]
+ def get_light(self, x, y):
+ return self.lights[x][y]
+ def get_lights(self):
+ return [ [ self.rig.select('$side={y}[$sequence={x}]'.format(y=y, x=x))
+ for y in ('bot', 'top') ]
+ for x in xrange(1, self.WIDTH+1)]
-def demo(lights, rig):
- """Do some light things."""
- #fish = fish_render.Fish(0, 0, 15, 1.5, color.black, 0.05 / constants.FRAME_RATE)
- #fish = fish_render.Fish(0, 0, 23, 1.5, color.RGB(193 / 255, 68 / 255, 227 / 255), 0.05 / constants.FRAME_RATE)
- fish = fish_render.Fish(0, 0, 23, 1.5, color.black, 0.05 / constants.FRAME_RATE)
- bridge = fish_render.Bridge(lights, fish, rig)
- current_time = time.time()
- count = 0
- while True:
- bridge.update()
- if count % constants.FRAME_RATE == 0:
- time_delta = time.time() - current_time
- print(time_delta)
- current_time = time.time()
- #time.sleep(1 / constants.FRAME_RATE)
- count += 1
def main():
- """Run show."""
- if have_lumiversepython:
- rig = lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
- else:
- rig = DummyRig(200, 2)
- rig.init()
- lights = get_all_lights(rig)
- demo(lights, rig)
+ bridge = Bridge()
+ show = FishShow(bridge)
+ #show = SunriseShow(bridge)
+ show.run(framerate=FRAME_RATE)
-if __name__ == '__main__':
- main()
+main() \ No newline at end of file