summaryrefslogtreecommitdiffstats
path: root/color.py
diff options
context:
space:
mode:
Diffstat (limited to 'color.py')
-rw-r--r--color.py13
1 files changed, 12 insertions, 1 deletions
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)