From cc3d2cd333f6c0c18a201d4ede36b1c62e9caef8 Mon Sep 17 00:00:00 2001 From: group1 Date: Thu, 13 Oct 2016 23:51:42 -0400 Subject: Package include path fix and add optimization for computing coverage --- ShowRunner.py | 4 ++-- fish_show.py | 4 +++- webapp/run.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ShowRunner.py b/ShowRunner.py index 05877ed..0357efd 100644 --- a/ShowRunner.py +++ b/ShowRunner.py @@ -10,8 +10,8 @@ from run import server_thread, send_queue, recv_queue def run_show(): server_thread.start() bridge = Bridge() - SunriseShow(bridge, send_queue=recv_queue, recv_queue=send_queue).run(framerate=FRAME_RATE) +# SunriseShow(bridge, send_queue=recv_queue, recv_queue=send_queue).run(framerate=FRAME_RATE) FishShow(bridge, send_queue=recv_queue, recv_queue=send_queue).run(framerate=FRAME_RATE) print "done!" -run_show() \ No newline at end of file +run_show() diff --git a/fish_show.py b/fish_show.py index 6677ddd..84b0516 100644 --- a/fish_show.py +++ b/fish_show.py @@ -89,6 +89,7 @@ class Fish(object): class Light(object): """Represent a bridge light and its state.""" + __slots__=('light', 'color', 'transitioning_to', 'x', 'y', 'step') def __init__(self, x, y, light): """Store all facts about a light.""" self.light = light @@ -112,7 +113,8 @@ class Light(object): new_color = new_background for fish in fishes: coverage = compute_coverage(fish, self.x, self.y) - new_color = coverage * fish.color + (1 - coverage) * new_color + if coverage > 0.01: + new_color = coverage * fish.color + (1 - coverage) * new_color self.light.setRGBRaw( *map(lambda x: clamp(0, x, 1), new_color.components) ) diff --git a/webapp/run.py b/webapp/run.py index 2290f41..fb270a9 100755 --- a/webapp/run.py +++ b/webapp/run.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys -sys.path.append('packages') +sys.path.append('webapp/packages') import threading -- cgit v1.3.1 From 5df1159bec104dc6541a186bca0770a85a13bc68 Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 16 Oct 2016 22:19:49 -0400 Subject: Go faster --- fish_show.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/fish_show.py b/fish_show.py index e410895..2f4716b 100644 --- a/fish_show.py +++ b/fish_show.py @@ -11,17 +11,18 @@ from fish_types import Fish class Light(object): """Represent a bridge light and its state.""" - __slots__=('light', 'color', 'transitioning_to', 'x', 'y', 'step') + __slots__=('light', 'color', 'transitioning_to', 'x', 'y', 'step', 'result_color') def __init__(self, x, y, light): """Store all facts about a light.""" self.light = light self.color = color.black + self.result_color = self.color self.transitioning_to = self.color self.step = 0 self.x = x self.y = y - def update(self, depth, fishes): + def update_base(self, depth): """Change color depending on where the fish is.""" if abs(self.transitioning_to - self.color) <= self.step: self.transitioning_to = pick_HSV(depth).to_RGB() @@ -32,16 +33,20 @@ class Light(object): ) self.color = new_background - new_color = new_background - for fish in fishes: - coverage = compute_coverage(fish, self.x, self.y) - if coverage > 0.01: - fish_color = fish.color_at(self.x, self.y) - new_color = coverage * fish_color + (1 - coverage) * new_color + self.result_color = new_background + + def update_fish(self, fish): + coverage = compute_coverage(fish, self.x, self.y) + fish_color = fish.color_at(self.x, self.y) + self.result_color = coverage * fish_color + (1 - coverage) * self.result_color + + def blit(self): self.light.setRGBRaw( - *map(lambda x: clamp(0, x, 1), new_color.components) + *map(lambda x: clamp(0, x, 1), self.result_color.components) ) + + def compute_coverage(fish, x, y): """Calculate the coverage of a fish over a box.""" middle_of_fish = fish.x + fish.width / 2 @@ -93,8 +98,8 @@ class FishShow(Show): MAX_DEPTH = 6 def init(self): - self.lights = [Light(x, y, self.bridge.get_light(x, y)) - for y in xrange(self.bridge.HEIGHT) + self.lights = [[Light(x, y, self.bridge.get_light(x, y)) + for y in xrange(self.bridge.HEIGHT)] for x in xrange(self.bridge.WIDTH)] self.fishes = set() self.tick_count = 0 @@ -106,11 +111,23 @@ class FishShow(Show): new_fish = Fish.by_type(event[1]['type']) self.fishes.add(new_fish) + for col in self.lights: + for light in col: + light.update_base(self.depth) + for fish in list(self.fishes): if not fish.update(): self.fishes.remove(fish) - for light in self.lights: - light.update(self.depth, self.fishes) + + for x in xrange(int(fish.x), int(fish.x+fish.width+1)): + if x < len(self.lights): + for light in self.lights[x]: + light.update_fish(fish) + + for col in self.lights: + for light in col: + light.blit() + self.tick_count += 1 if self.tick_count % self.TICKS_PER_DEPTH == 0: -- cgit v1.3.1 From d62c186e42bb84ef42db5097ef9f291a57197a7e Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 16 Oct 2016 22:21:11 -0400 Subject: Don't crash when it's not a fish --- fish_show.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fish_show.py b/fish_show.py index 2f4716b..6abf3bc 100644 --- a/fish_show.py +++ b/fish_show.py @@ -109,7 +109,8 @@ class FishShow(Show): event = self.recv_event() if event and event[0] == 'spawn': new_fish = Fish.by_type(event[1]['type']) - self.fishes.add(new_fish) + if new_fish: + self.fishes.add(new_fish) for col in self.lights: for light in col: -- cgit v1.3.1 From 73f0ef7fd327e5376b4d6b27f88cefac25c484d1 Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 16 Oct 2016 22:41:14 -0400 Subject: Eel --- fish_types.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fish_types.py b/fish_types.py index 61cd36a..d37a259 100644 --- a/fish_types.py +++ b/fish_types.py @@ -11,6 +11,9 @@ class Fish(object): Must override color (or color_at), drag, width, height, tailThreshold, tailDuration, tailAccelMag """ + + is_diamond = True + def __init__(self, x=None, y=None): """Create fish with default parameters.""" if x is not None: @@ -219,27 +222,29 @@ class Stingray(Fish): class Eel(Fish): - color = C.HSV(109/360, 83/100, 35/100).to_RGB() + color = C.HSV(109/360, 83/100, 0/100).to_RGB() drag = -0.09 - width = 50 + width = 30 height = 2 tailThreshold = 0.7 tailDuration = 2 - tailAccelMag = 0.1 + tailAccelMag = 0.2 front_offset = 0 y = 0 + is_diamond = False def alpha_at(self, x, y): rel_x = x - self.x - rel_y = y - self.y eel_height = math.sin( 2 * math.pi * (rel_x + self.front_offset) / self.width ) / 2 + 0.5 - y_blend = abs(rel_y - eel_height) - if y_blend > 0.5: + y_blend = abs(y - eel_height) + if y_blend > 0.75: return 0 - return (1 - y_blend) + if y_blend < 0.25: + return 1 + return 1 - y_blend def update(self): self.front_offset += abs(self.speed) -- cgit v1.3.1 From 65d62033231e7ba8e99b341aa13a6ed2b63920a6 Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 16 Oct 2016 23:05:41 -0400 Subject: Jellyfish --- fish_types.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fish_types.py b/fish_types.py index d37a259..ce15703 100644 --- a/fish_types.py +++ b/fish_types.py @@ -26,6 +26,7 @@ class Fish(object): self.y = 0.5 self.speed = C.Vector(0, 0) self.tailAcceleration = C.Vector(self.tailAccelMag, 0) + self.tailThresholdCurrent = self.tailThreshold self.tailMoving = False self.tailMoveCount = 0 if not hasattr(self, 'theta_scale'): @@ -58,9 +59,11 @@ class Fish(object): return False self.speed += self.drag * self.speed - if abs(self.speed) < self.tailThreshold: + if abs(self.speed) < self.tailThresholdCurrent: self.tailMoving = True - self.tailThreshold = rand_in_range(0.5, 1.4) + self.tailThresholdCurrent = max(rand_in_range( + self.tailThreshold - 0.1, self.tailThreshold + 0.1 + ), 0.0001) self.fix_direction() if self.tailMoveCount > self.tailDuration: self.tailMoveCount = 0 @@ -100,12 +103,12 @@ class Fish(object): class Jellyfish(Fish): color = C.HSV(298/360, 89/100, 53/100).to_RGB() - drag = -0.01 + drag = -0.1 width = 15 height = 1.5 - tailThreshold = 0.001 - tailDuration = 4 - tailAccelMag = 0.001 + tailThreshold = 0.2 + tailDuration = 6 + tailAccelMag = 0.25 class Dolphin(Fish): -- cgit v1.3.1 From 54565fbc7c0fe1d30c98740d146bbb1723f5408a Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 16 Oct 2016 23:23:56 -0400 Subject: Whale --- fish_types.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fish_types.py b/fish_types.py index ce15703..b66c293 100644 --- a/fish_types.py +++ b/fish_types.py @@ -112,13 +112,13 @@ class Jellyfish(Fish): class Dolphin(Fish): - color = C.HSV(18/360, 0/100, 40/100).to_RGB() + color = C.HSV(18/360, 0/100, 10/100).to_RGB() drag = -0.09 width = 35 height = 1.5 tailThreshold = 0.7 tailDuration = 2 - tailAccelMag = 0.8 + tailAccelMag = 0.4 gravity = C.Vector(0, -0.01) direction_fixed = False @@ -162,7 +162,7 @@ class Boat(Fish): class Dory(Fish): # Need to try this on the bridge - color = C.HSV(235/360, 100/100, 88/100).to_RGB() + color = C.HSV(235/360, 100/100, 100/100).to_RGB() drag = -0.1 width = 23 height = 1.5 @@ -172,7 +172,7 @@ class Dory(Fish): class Nemo(Fish): - color = C.HSV(31/360, 100/100, 50/100).to_RGB() + color = C.HSV(40/360, 100/100, 10/100).to_RGB() drag = -0.09 width = 23 height = 1.5 @@ -183,7 +183,7 @@ class Nemo(Fish): class Whale(Fish): drag = -0.2 - width = 50 + width = 80 height = 2 tailThreshold = 0.7 tailDuration = 3 @@ -192,10 +192,10 @@ class Whale(Fish): y = 0 - white_x_min = 30 - white_x_width = 8 - white_y_min = 1 - white_y_height = 1 + white_x_min = 58 + white_x_width = 6 + white_y_min = 1.45 + white_y_height = 0.5 def color_at(self, x, y): """Mostly copied from compute_coverage. -- cgit v1.3.1 From 80041811f4fe9fd61fe69d39f6b6441902e4ba01 Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 16 Oct 2016 23:25:13 -0400 Subject: Stingray --- fish_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_types.py b/fish_types.py index b66c293..3bb3033 100644 --- a/fish_types.py +++ b/fish_types.py @@ -215,7 +215,7 @@ class Whale(Fish): class Stingray(Fish): - color = C.HSV(0/360, 0/100, 50/100).to_RGB() + color = C.HSV(0/360, 0/100, 10/100).to_RGB() drag = -0.09 width = 15 height = 2 -- cgit v1.3.1 From 2602b777fbe9b7a4448b1c4cec9ac4a4fd7002c1 Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 16 Oct 2016 23:26:40 -0400 Subject: Shark --- fish_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_types.py b/fish_types.py index 3bb3033..6d24675 100644 --- a/fish_types.py +++ b/fish_types.py @@ -260,7 +260,7 @@ class Eel(Fish): class Shark(Fish): - color = C.HSV(0/360, 0/100, 50/100).to_RGB() + color = C.HSV(0/360, 0/100, 10/100).to_RGB() drag = -0.2 width = 50 height = 2 -- cgit v1.3.1