summaryrefslogtreecommitdiffstats
path: root/color.py
diff options
context:
space:
mode:
authorRaymond Hogenson <rayhogenson@openmailbox.org>2016-09-27 23:12:49 -0400
committerRaymond Hogenson <rayhogenson@openmailbox.org>2016-09-27 23:12:49 -0400
commited0c631003b556e2e84f21bf4ebbf03891763641 (patch)
treeced193b8214d8c1bf7f1e8b4dd1d16d3c3e104d4 /color.py
parentCreate .gitignore file (diff)
parentAdd bridge simulator and cleanup code (diff)
downloadbridge-ed0c631003b556e2e84f21bf4ebbf03891763641.tar.zst
Merge branch 'master' of github.com:rayhogenson/bridge
Diffstat (limited to 'color.py')
-rw-r--r--color.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/color.py b/color.py
index 2b51701..84ece9d 100644
--- a/color.py
+++ b/color.py
@@ -11,19 +11,19 @@ class Vector(object):
def __add__(self, other):
"""Add two vectors."""
- return Vector(
- *map(lambda x, y: x + y, zip(self.components, other.components))
+ return self.__class__(
+ *map(lambda (x, y): x + y, zip(self.components, other.components))
)
def __sub__(self, other):
"""Subtract two vectors."""
- return Vector(
- *map(lambda x, y: x - y, zip(self.components, other.components))
+ return self.__class__(
+ *map(lambda (x, y): x - y, zip(self.components, other.components))
)
def __mul__(self, other):
"""Multiply a vector by a constant."""
- return Vector(*map(lambda x: x * other, self.components))
+ return self.__class__(*map(lambda x: x * other, self.components))
def __rmul__(self, other):
"""Multiply a constant by a vector."""
@@ -33,16 +33,16 @@ class Vector(object):
"""Return the 2-norm of the vector."""
return math.sqrt(sum(map(lambda x: x * x, self.components)))
- def __div__(self, scalar):
+ def __truediv__(self, scalar):
"""Return self * 1 / scalar."""
return self * (1 / scalar)
-def HSV(Vector):
+class HSV(Vector):
"""HSV 3-vector."""
def __init__(self, hue, saturation, value):
"""Initialize with hue, saturation, and value."""
- super(Vector, self).__init__(hue, saturation, value)
+ super(HSV, self).__init__(hue, saturation, value)
def to_RGB(self):
"""Convert to an RGB vector."""
@@ -61,11 +61,11 @@ def HSV(Vector):
return self.components[2]
-def RGB(Vector):
+class RGB(Vector):
"""RGB 3-vector."""
def __init__(self, r, g, b):
"""Initialize with red green and blue."""
- super(Vector, self).__init__(r, g, b)
+ super(RGB, self).__init__(r, g, b)
def to_HSV(self):
"""Convert to HSV vector."""