diff options
| author | Aaron Perley <aaron.perley@gmail.com> | 2016-09-27 21:39:02 -0400 |
|---|---|---|
| committer | Aaron Perley <aaron.perley@gmail.com> | 2016-09-27 21:39:02 -0400 |
| commit | 6e265cfa5002a5667681733eae08357f2b9695e5 (patch) | |
| tree | e82e90871c04252114421794849bed152ee2700c /color.py | |
| parent | 78fde3bb014ecd8e2368f2cc088839aecd0ca1ed (diff) | |
| download | bridge-6e265cfa5002a5667681733eae08357f2b9695e5.tar.zst | |
Add bridge simulator and cleanup code
Diffstat (limited to 'color.py')
| -rw-r--r-- | color.py | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -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.""" |
