summaryrefslogtreecommitdiffstats
path: root/fish_show.py
diff options
context:
space:
mode:
Diffstat (limited to 'fish_show.py')
-rw-r--r--fish_show.py87
1 files changed, 3 insertions, 84 deletions
diff --git a/fish_show.py b/fish_show.py
index 6677ddd..62a07c9 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):
@@ -112,7 +34,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
+ 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)
)
@@ -194,7 +117,3 @@ class FishShow(Show):
if self.depth > self.MAX_DEPTH:
self.stop()
-
-
-def rand_in_range(low, high):
- return random.random() * (high - low) + low