summaryrefslogtreecommitdiff
path: root/color/colormap.py
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-08-08 15:37:21 -0400
committerStan Seibert <stan@mtrr.org>2011-08-08 15:37:21 -0400
commitfd2cba0f96e2d145e6a2b6e3df91cb6e942c114c (patch)
treebcb6b902c10d8cafa00e228b634e5a0fbd6bf6ae /color/colormap.py
parent09e042b8888342ed8fc7a8c5b05ea1caa47a3842 (diff)
parented642493fccbcf13efef5491f73241c6a9434ad8 (diff)
downloadchroma-fd2cba0f96e2d145e6a2b6e3df91cb6e942c114c.tar.gz
chroma-fd2cba0f96e2d145e6a2b6e3df91cb6e942c114c.tar.bz2
chroma-fd2cba0f96e2d145e6a2b6e3df91cb6e942c114c.zip
Merge Tony's changes.
Diffstat (limited to 'color/colormap.py')
-rw-r--r--color/colormap.py24
1 files changed, 5 insertions, 19 deletions
diff --git a/color/colormap.py b/color/colormap.py
index b3761ae..e5bd73e 100644
--- a/color/colormap.py
+++ b/color/colormap.py
@@ -1,27 +1,13 @@
import numpy as np
+import matplotlib.cm as cm
-import matplotlib.pyplot as plt
-
-def map_to_color(a, range=None):
+def map_to_color(a, range=None, map=cm.hsv):
a = np.asarray(a)
if range is None:
range = (a.min(), a.max())
- x = np.linspace(0, np.pi, 100)
-
- yr = np.cos(x)**2
- yr[x > np.pi/2] = 0.0
- yg = np.sin(x)**2
- yb = np.cos(x)**2
- yb[x < np.pi/2] = 0.0
-
- #plt.plot(x, yr, 'r-', x, yb, 'b-', x, yg, 'g-')
- #plt.show()
-
- ax = np.pi*(a - range[0])/(range[1]-range[0])
+ ax = (a - range[0])/(range[1]-range[0])
- r = (np.interp(ax, x, yr)*255).astype(np.uint32)
- g = (np.interp(ax, x, yg)*255).astype(np.uint32)
- b = (np.interp(ax, x, yb)*255).astype(np.uint32)
+ rgba = (map(ax)*255).astype(np.uint32)
- return r << 16 | g << 8 | b
+ return rgba[:,0] << 16 | rgba[:,1] << 8 | rgba[:,2]