diff options
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 |