From 9b60deedc508c74b249fd1da0776b5a719322807 Mon Sep 17 00:00:00 2001 From: group1 Date: Sun, 9 Oct 2016 23:13:51 -0400 Subject: Realistic small fish movement --- color.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'color.py') diff --git a/color.py b/color.py index 058abb4..c65252b 100644 --- a/color.py +++ b/color.py @@ -7,7 +7,7 @@ class Vector(object): __slots__ = ('x', 'y', 'z') """3-dimensional vector class.""" - def __init__(self, x, y, z): + def __init__(self, x=0, y=0, z=0): """Create a vector from its components.""" self.x = x self.y = y @@ -40,6 +40,17 @@ class Vector(object): def __eq__(self, other): return self.x == other.x and self.y == other.y and self.z == other.z + def unit(self): + return self / abs(self) + + def rot2d(self, theta): + costheta = math.cos(theta) + sintheta = math.sin(theta) + new_x = self.x * costheta - self.y * sintheta + new_y = self.x * sintheta + self.y * costheta + return self.__class__(new_x, new_y) + + @property def components(self): return (self.x, self.y, self.z) -- cgit v1.3.1