diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2013-02-28 14:59:55 -0500 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2013-02-28 14:59:55 -0500 |
commit | e4360a48435cc762855d356b208b5544e6f40c4b (patch) | |
tree | 71c6c83c247cb07495265b93ec062eefc3e928a8 /beam_tracing/python/colorGradient.py | |
parent | a08ed173692ce16b79002733003049ec32a02485 (diff) | |
download | wgmr-e4360a48435cc762855d356b208b5544e6f40c4b.tar.gz wgmr-e4360a48435cc762855d356b208b5544e6f40c4b.zip |
Added python version of mode-matching code by Bain Bronner
Diffstat (limited to 'beam_tracing/python/colorGradient.py')
-rw-r--r-- | beam_tracing/python/colorGradient.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/beam_tracing/python/colorGradient.py b/beam_tracing/python/colorGradient.py new file mode 100644 index 0000000..dd9c856 --- /dev/null +++ b/beam_tracing/python/colorGradient.py @@ -0,0 +1,32 @@ +import colorsys
+import numpy as np
+
+def colorGradient(pos, baseColorRGB, nColors):
+# returns rgb=[R,G,B] components from the brightness gradient of the base color
+# base_color_rgb - [R,G,B] of the base color
+# Ncolors - number of positions in gradient
+
+ # color map as gradient of particular color
+ # starting values
+ hsv_s = colorsys.rgb_to_hsv(baseColorRGB[0], baseColorRGB[1], baseColorRGB[2])
+ hue_f = hsv_s[0]
+ sat_f = hsv_s[1]
+ val_f = hsv_s[2]
+ # stop values
+ hue_s = hue_f
+ sat_s = 0
+ val_s = 1
+ hue = np.linspace(hue_s, hue_f, nColors)
+ sat = np.linspace(sat_s, sat_f, nColors)
+ val = np.linspace(val_s, val_f, nColors)
+
+ # check that pos is with in the reach
+ pos = np.floor(pos)
+ if pos < 1:
+ pos = 1
+ if pos > nColors:
+ pos = nColors
+
+ pos = int(pos)
+ RGB = colorsys.hsv_to_rgb(hue[pos-1], sat[pos-1], val[pos-1])
+ return RGB
\ No newline at end of file |