summaryrefslogtreecommitdiffstats
path: root/fish_show.py
diff options
context:
space:
mode:
Diffstat (limited to 'fish_show.py')
-rw-r--r--fish_show.py89
1 files changed, 4 insertions, 85 deletions
diff --git a/fish_show.py b/fish_show.py
index 84b0516..e410895 100644
--- a/fish_show.py
+++ b/fish_show.py
@@ -6,85 +6,7 @@ import constants
from constants import *
import math
from show import Show
-
-
-
-class Fish(object):
- """Object displayed on the bridge, probably a fish."""
- def __init__(self, x, y, width, height, color, step):
- """Create fish with default parameters."""
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.color = color
- self.speed = step
- self.step = step
-
- self.speed = Vector(0.1, 0)
- self.drag = -0.09
-
- self.tailAccelMag = 0.4
- self.tailAcceleration = Vector(self.tailAccelMag, 0)
- self.tailDuration = 2
- self.tailMoving = False
- self.tailThreshold = 0.7
- self.tailMoveCount = 0
-
- def update(self):
- """Swim gently to the other side of the bridge."""
- if self.x > constants.BRIDGE_WIDTH or self.x < -self.width:
- return False
-
- self.speed += self.drag * self.speed
- if abs(self.speed) < self.tailThreshold:
- self.tailMoving = True
- self.tailThreshold = rand_in_range(0.5, 1.4)
- self.fix_direction()
- if self.tailMoveCount > self.tailDuration:
- self.tailMoveCount = 0
- self.tailMoving = False
- if self.tailMoving:
- self.speed += self.tailAcceleration
- self.tailMoveCount += 1
- self.x += self.speed.components[0]
- self.y += self.speed.components[1]
-
- return True
-
- def fix_direction(self):
- min_theta = -0.32
- max_theta = 0.32
- if self.y < 0:
- min_theta = 0
- if self.y > 1:
- max_theta = 0
-
- #theta = rand_in_range(min_theta, max_theta)
- theta = random.gauss((max_theta+min_theta)/2, (max_theta - min_theta)/12)
- self.tailAcceleration = Vector(self.tailAccelMag, 0).rot2d(theta)
-
- @classmethod
- def by_type(cls, fish_type):
- if (fish_type == 'jellyfish'):
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'dolphin':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'boat':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'dory':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'nemo':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'whale':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'stingray':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'eel':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
- if fish_type == 'shark':
- return cls(0, 0.5, 23, 1.5, color.black, 1)
-
+from fish_types import Fish
class Light(object):
@@ -114,7 +36,8 @@ class Light(object):
for fish in fishes:
coverage = compute_coverage(fish, self.x, self.y)
if coverage > 0.01:
- new_color = coverage * fish.color + (1 - coverage) * new_color
+ fish_color = fish.color_at(self.x, self.y)
+ new_color = coverage * fish_color + (1 - coverage) * new_color
self.light.setRGBRaw(
*map(lambda x: clamp(0, x, 1), new_color.components)
)
@@ -130,7 +53,7 @@ def compute_coverage(fish, x, y):
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 * scale
+ return coverage * scale * fish.alpha_at(x, y)
def pick_HSV(depth):
@@ -196,7 +119,3 @@ class FishShow(Show):
if self.depth > self.MAX_DEPTH:
self.stop()
-
-
-def rand_in_range(low, high):
- return random.random() * (high - low) + low