diff options
Diffstat (limited to 'twinkle.py')
| -rwxr-xr-x | twinkle.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/twinkle.py b/twinkle.py new file mode 100755 index 0000000..a2cb3d2 --- /dev/null +++ b/twinkle.py @@ -0,0 +1,112 @@ +#!/usr/bin/python2 +"""Simple demo of twinkle lights.""" +from __future__ import division +import color +import constants +#from DummyRig import DummyRig +from fish_render import * +import fish_render +from constants import * +import time +import random +try: + import lumiversepython +except ImportError: + have_lumiversepython = False +else: + have_lumiversepython = True + +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 flip(): + """Return 0 with 99.9% prob. & 1 with .1% prob.""" + # should be black most of the time + return random.random() < 0.0005 + + +def twinkle(lights, rig): + """Try to do some light things.""" + light_status = [ + { + 'is_increasing': True, + 'is_on': False, + 'change': random_change(), + 'light': light, + 'intensity': 0, + } + for light_col in lights for light in light_col + ] + shooting_stars = list() + while True: + if random.random() < 1: + shooting_stars.append([random.randint(1, 180), random.random() < 0.5, 0]) + for light_s in light_status: + is_increasing = light_s['is_increasing'] + is_on = light_s['is_on'] + change = light_s['change'] + light = light_s['light'] + intensity = light_s['intensity'] + # R and G are either 0 or 1 + if not is_on: + if flip(): + is_on = True + is_increasing = True + change = 1.5 / FRAME_RATE + light_s['is_on'] = is_on + light_s['is_increasing'] = is_increasing + light_s['change'] = change + else: + continue + intensity = clamp(0, intensity + change * (int(is_increasing) * 2 - 1), 1) + light.light.setRGBRaw(intensity, intensity, intensity) + light_s['intensity'] = intensity + if intensity == 0: + light_s['is_on'] = False + if intensity == 1: + light_s['is_increasing'] = False + for i, star in enumerate(shooting_stars): + star[2] += 1 + if star[2] > 10: + for dx in range(-6, 7): + light_status[star[0] + dx]['light'].light.setRGBRaw(0, 0, 0) + del shooting_stars[i] + continue + star[0] += int(star[1]) * 2 - 1 + for dx in range(-6, 7): + intensity = 1 - 1 / 6 * abs(dx) + light_status[star[0] + dx]['light'].light.setRGBRaw(intensity, intensity, intensity) + rig.updateOnce() + time.sleep(1 / FRAME_RATE) + +def sunrise(lights, rig): + #rig.select('$side={y}[$sequence={x}]'.format(y=y, x=x)) + rig.select("$side=top[$panel=27|$panel=28]") + rig.updateOnce() + time.sleep(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) + #for light in lights: + # light.setRGBRaw(0, 0, 0) + rig.updateOnce() + time.sleep(3) + twinkle(lights, rig) + +if __name__ == '__main__': + main() |
