summaryrefslogtreecommitdiff
path: root/chroma/color/colormap.py
diff options
context:
space:
mode:
Diffstat (limited to 'chroma/color/colormap.py')
-rw-r--r--chroma/color/colormap.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/chroma/color/colormap.py b/chroma/color/colormap.py
new file mode 100644
index 0000000..6f3e056
--- /dev/null
+++ b/chroma/color/colormap.py
@@ -0,0 +1,20 @@
+import numpy as np
+import matplotlib.cm as cm
+
+def map_to_color(a, range=None, map=cm.hsv, weights=None):
+ a = np.asarray(a)
+ if range is None:
+ range = (a.min(), a.max())
+
+ ax = (a - range[0])/(range[1]-range[0])
+
+ frgba = map(ax)
+
+ if weights is not None:
+ frgba[:,0] *= weights
+ frgba[:,1] *= weights
+ frgba[:,2] *= weights
+
+ rgba = (frgba*255).astype(np.uint32)
+
+ return rgba[:,0] << 16 | rgba[:,1] << 8 | rgba[:,2]