summaryrefslogtreecommitdiffstats
path: root/fish_show.py
diff options
context:
space:
mode:
Diffstat (limited to 'fish_show.py')
-rw-r--r--fish_show.py52
1 files changed, 44 insertions, 8 deletions
diff --git a/fish_show.py b/fish_show.py
index cda4174..f3ccf25 100644
--- a/fish_show.py
+++ b/fish_show.py
@@ -18,15 +18,51 @@ class Fish(object):
self.speed = step
self.step = step
+ self.speed = Vector(10, 0)
+ self.drag = -1
+
+ self.tailAcceleration = color.Vector(5, 0)
+ self.tailDuration = 2
+ self.tailMoving = False
+ self.tailThreshold = 5
+ self.tailMoveCount = 0
+
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)
+ self.speed += self.drag * self.speed / abs(self.speed)
+ if abs(self.speed) < self.tailThreshold:
+ self.tailMoving = True
+ 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]
+ #
+ # THIS NEEDS TO CHANGE
+ #
+ if self.x > constants.BRIDGE_WIDTH:
+ self.x = -self.width
+ if self.x < -self.width:
+ self.x = constants.BRIDGE_WIDTH
+ if self.y < -self.width:
+ self.y = constants.BRIDGE_HEIGHT + self.height
+ if self.y > -self.height:
+ self.y = constants.BRIDGE_HEIGHT
+
+ def fix_direction(self, theta=None):
+ if theta is None:
+ theta = random.random * math.pi / 2 - math.pi / 4
+ costheta = math.cos(theta)
+ sintheta = math.sin(theta)
+ speedx = self.tailAcceleration.components[0]
+ speedy = self.tailAcceleration.components[1]
+ data.tailAcceleration = color.Vector(
+ speedx * costheta - speedy * sintheta,
+ speedx * sintheta + speedy * costheta
+ )
class Light(object):
"""Represent a bridge light and its state."""
@@ -114,4 +150,4 @@ class FishShow(Show):
def update(self):
self.fish.update()
for light in self.lights:
- light.update(self.fish) \ No newline at end of file
+ light.update(self.fish)