summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hogenson <rayhogenson@openmailbox.org>2016-09-18 23:26:06 -0400
committerRaymond Hogenson <rayhogenson@openmailbox.org>2016-09-18 23:26:06 -0400
commit5c45fd2b0c83e50288184813e5b4724a391435de (patch)
treef9f08c17d17f4d4a645efc724ed778be6f7052c8
downloadbridge-5c45fd2b0c83e50288184813e5b4724a391435de.tar.zst
Add script from first meeting
The script kind of strobes the lights gently and the parameters are configurable with global variables. Right now, the only color used is blue.
-rw-r--r--bridge.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/bridge.py b/bridge.py
new file mode 100644
index 0000000..6e2ce02
--- /dev/null
+++ b/bridge.py
@@ -0,0 +1,80 @@
+#!/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('$side={}[$sequence={}]'.format(j, i)) for j in ['top', 'bot'] for i in range(1, 200)]
+
+
+def restrict(low, x, high):
+ """Return a value low <= v <= high, and equal to x if possible."""
+ return max(low, min(x, high))
+
+
+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)
+ 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):
+ """Do some light things."""
+ light_status = [
+ {
+ 'is_increasing': True,
+ 'change': random_change(),
+ 'light': light,
+ 'current_value': 0,
+ }
+ for light in lights
+ ]
+ while True:
+ for light_s in light_status:
+ is_increasing = light_s['is_increasing']
+ change = light_s['change']
+ light = light_s['light']
+ current_value = light_s['current_value']
+ new_value = restrict(
+ 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 in [MIN_VALUE, MAX_VALUE]:
+ light_s['is_increasing'] = not is_increasing
+ light_s['change'] = random_change()
+ rig.updateOnce()
+ 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():
+ """Run show."""
+ rig = lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
+ rig.init()
+ lights = get_all_lights(rig)
+ demo(lights, rig)
+ #panels(lights, rig)
+
+if __name__ == '__main__':
+ main()