diff options
| author | Raymond Hogenson <rayhogenson@openmailbox.org> | 2016-09-30 21:45:03 -0400 |
|---|---|---|
| committer | Raymond Hogenson <rayhogenson@openmailbox.org> | 2016-09-30 21:45:03 -0400 |
| commit | 6d33edbed15bacae2698cba32d60c812e54f5b7b (patch) | |
| tree | 6e814fa90d90801b8fcd2418504203ddf950691e | |
| parent | dd7dd93d9e1ee2e0095f0fa403a499b69aa289a8 (diff) | |
| download | bridge-6d33edbed15bacae2698cba32d60c812e54f5b7b.tar.zst | |
Meeting 2
| -rwxr-xr-x | bridge.py | 18 | ||||
| -rw-r--r-- | constants.py | 22 | ||||
| -rw-r--r-- | fish_render.py | 44 |
3 files changed, 63 insertions, 21 deletions
@@ -1,15 +1,16 @@ #!/usr/bin/python2 """Simple demo of oscillating colors.""" -from __future__ import division, unicode_literals +from __future__ import division, print_function import color import constants -from DummyRig import DummyRig import fish_render import time +import random try: import lumiversepython except ImportError: have_lumiversepython = False + from DummyRig import DummyRig else: have_lumiversepython = True @@ -27,11 +28,20 @@ def get_all_lights(rig): def demo(lights, rig): """Do some light things.""" - fish = fish_render.Fish(0, 0, 2, 1, color.red, 1 / constants.FRAME_RATE) + #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() - time.sleep(1 / constants.FRAME_RATE) + 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(): diff --git a/constants.py b/constants.py index e19c127..1685c5a 100644 --- a/constants.py +++ b/constants.py @@ -1,10 +1,22 @@ """Constants that may be tweaked in the future.""" from __future__ import division, unicode_literals -FRAME_RATE = 10 #44 +FRAME_RATE = 22 MIN_VALUE = 0 MAX_VALUE = 1 -MAX_TIME = 4 -MIN_TIME = 0.3 -MAX_HUE = 169 / 360 -MIN_HUE = 250 / 360 +MAX_TIME = 2 +MIN_TIME = 0.1 +MIN_HUE = 207 / 360 +MAX_HUE = 250 / 360 +MAX_SATURATION = 1 +MIN_SATURATION = 0.5 +MIN_VALUE = 0.3 +MAX_VALUE = 1 + +# shallow +MIN_HUE = 169 / 360 +MAX_HUE = 250 / 360 +MAX_SATURATION = 1 +MIN_SATURATION = 0.5 +MIN_VALUE = 0.3 +MAX_VALUE = 1 diff --git a/fish_render.py b/fish_render.py index 4924016..18aecac 100644 --- a/fish_render.py +++ b/fish_render.py @@ -2,6 +2,9 @@ from __future__ import division, unicode_literals import color import random +import constants +from constants import * +import math class Fish(object): """Object displayed on the bridge, probably a fish.""" @@ -18,6 +21,12 @@ class Fish(object): def update(self): """Swim gently to the other side of the bridge.""" self.x += self.step + if self.x > 200: + self.x = 0 + self.y = 0.25 + 0.25 * math.sin(math.pi * self.x / 10) + #theta = random.random() * math.pi / 2 - math.pi / 4 + #self.y += 0.01 * math.sin(theta) + #print(self.y) class Light(object): @@ -33,7 +42,7 @@ class Light(object): def update(self, fish): """Change color depending on where the fish is.""" - if abs(self.transitioning_to - self.color) < self.step: + if abs(self.transitioning_to - self.color) <= self.step: self.transitioning_to = pick_HSV().to_RGB() self.step = (random_change() * abs(self.color - self.transitioning_to)) @@ -41,7 +50,13 @@ class Light(object): self.color, self.transitioning_to, self.step ) coverage = compute_coverage(fish, self.x, self.y) + #coverage *= coverage new_color = coverage * fish.color + (1 - coverage) * new_background + #new_color = new_background + self.color = new_background + if self.x == 30 and self.y == 0: + pass + #print(self.color.r(), self.color.g(), self.color.b()) self.light.setRGBRaw( *map(lambda x: clamp(0, x, 1), new_color.components) ) @@ -61,24 +76,28 @@ class Bridge(object): for y, light in enumerate(light_col): self.fish.update() light.update(self.fish) - self.rig.updateOnce() + self.rig.updateOnce() def compute_coverage(fish, x, y): """Calculate the coverage of a fish over a box.""" - min_x = max(x, fish.x) - max_x = min(x+1, fish.x + fish.width) - min_y = max(y, fish.y) - max_y = min(y+1, fish.y + fish.height) + middle_of_fish = fish.x + fish.width / 2 + middle_of_panel = x + 0.5 + diff = abs(middle_of_fish - middle_of_panel) / (fish.width / 2) + scale = 1 - diff + min_x = min(max(x, fish.x), x + 1) + max_x = max(min(x+1, fish.x + fish.width), x) + min_y = min(max(y, fish.y), y + 1) + max_y = max(min(y+1, fish.y + fish.height), y) coverage = (max_x - min_x) * (max_y - min_y) - return coverage + return coverage * scale 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() + hue = random.random() * (constants.MAX_HUE - constants.MIN_HUE) + constants.MIN_HUE + saturation = random.random() * (MAX_SATURATION - MIN_SATURATION) + MIN_SATURATION + value = random.random() * (MAX_VALUE - MIN_VALUE) + MIN_VALUE return color.HSV(hue, saturation, value) @@ -88,12 +107,13 @@ def transition(start, end, step): return start diff_vector = end - start step_vector = diff_vector / abs(diff_vector) * step - return step_vector + start + result = step_vector + start + return result def random_change(): """Return a random amount that a light should change each frame.""" - min_time = int(MIN_TIME * FRAME_RATE) + min_time = int(constants.MIN_TIME * FRAME_RATE) max_time = int(MAX_TIME * FRAME_RATE) return 1 / random.randint(min_time, max_time) |
