summaryrefslogtreecommitdiffstats
path: root/fish_show.py
diff options
context:
space:
mode:
Diffstat (limited to 'fish_show.py')
-rw-r--r--fish_show.py48
1 files changed, 33 insertions, 15 deletions
diff --git a/fish_show.py b/fish_show.py
index 143cdad..a94a422 100644
--- a/fish_show.py
+++ b/fish_show.py
@@ -11,7 +11,7 @@ from fish_types import Fish
class Light(object):
"""Represent a bridge light and its state."""
- __slots__=('light', 'color', 'transitioning_to', 'x', 'y', 'step', 'result_color')
+ __slots__=('light', 'color', 'transitioning_to', 'x', 'y', 'step', 'result_color', 'fade_step')
def __init__(self, x, y, light):
"""Store all facts about a light."""
self.light = light
@@ -21,6 +21,7 @@ class Light(object):
self.step = 0
self.x = x
self.y = y
+ self.fade_step = 0
def update_base(self, depth):
"""Change color depending on where the fish is."""
@@ -45,6 +46,13 @@ class Light(object):
*map(lambda x: clamp(0, x, 1), self.result_color.components)
)
+ def fade_to_black(self, steps):
+ hue = self.color.to_HSV().h()
+ sat = self.color.to_HSV().s()
+ value = self.color.to_HSV().v()
+ new_color = color.HSV(hue, sat, value - value / steps * self.fade_step).to_RGB()
+ self.fade_step += 1
+ self.light.setRGBRaw(*map(lambda x: clamp(0, x, 1), new_color.components))
def compute_coverage(fish, x, y):
@@ -96,7 +104,7 @@ def clamp(low, x, high):
class FishShow(Show):
# 1 minute show
- TICKS_PER_DEPTH = FRAME_RATE * 10
+ TICKS_PER_DEPTH = FRAME_RATE * 75
MAX_DEPTH = 6
def init(self):
@@ -105,6 +113,7 @@ class FishShow(Show):
for x in xrange(self.bridge.WIDTH)]
self.fishes = set()
self.tick_count = 0
+ self.started_fade_tick = None
self.depth = 0
self.send_event('disable image', {'name': 'jellyfish'})
self.send_event('disable image', {'name': 'dolphin'})
@@ -145,31 +154,31 @@ class FishShow(Show):
if self.tick_count % self.TICKS_PER_DEPTH == 0:
self.depth += 1
print("DEPTH: ", self.depth)
- if depth == 1:
- """boat, dolphin"""
+ if self.depth == 1:
+ """boat, dolphin"""
self.send_event('enable image', {'name': 'boat'})
self.send_event('enable image', {'name': 'dolphin'})
- else if depth == 2:
- """dolphin, jellyfish"""
+ elif self.depth == 2:
+ """dolphin, jellyfish"""
self.send_event('disable image', {'name': 'boat'})
self.send_event('enable image', {'name': 'jellyfish'})
- else if depth == 3:
- """jellyfish, nemo, dory, whale"""
+ elif self.depth == 3:
+ """jellyfish, nemo, dory, whale"""
self.send_event('disable image', {'name': 'dolphin'})
self.send_event('enable image', {'name': 'nemo'})
self.send_event('enable image', {'name': 'dory'})
self.send_event('enable image', {'name': 'whale'})
- else if depth == 4:
- """nemo, dory, whale, shark"""
+ elif self.depth == 4:
+ """nemo, dory, whale, shark"""
self.send_event('disable image', {'name': 'jellyfish'})
self.send_event('enable image', {'name': 'shark'})
- else if depth == 5:
- """whale, shark, stingray"""
+ elif self.depth == 5:
+ """whale, shark, stingray"""
self.send_event('disable image', {'name': 'nemo'})
self.send_event('disable image', {'name': 'dory'})
self.send_event('enable image', {'name': 'stingray'})
- else if depth == 6:
- """stingray, eel"""
+ elif self.depth == 6:
+ """stingray, eel"""
self.send_event('disable image', {'name': 'whale'})
self.send_event('disable image', {'name': 'shark'})
self.send_event('enable image', {'name': 'eel'})
@@ -177,5 +186,14 @@ class FishShow(Show):
if self.depth > self.MAX_DEPTH:
self.send_event('disable image', {'name': 'stingray'})
self.send_event('disable image', {'name': 'eel'})
- self.stop()
+
+ fade_time = 5 # sec
+ if self.started_fade_tick is None:
+ self.started_fade_tick = self.tick_count
+ if self.tick_count > self.started_fade_tick + FRAME_RATE * fade_time:
+ self.stop()
+ return
+ for col in self.lights:
+ for light in col:
+ light.fade_to_black(fade_time * FRAME_RATE)