summaryrefslogtreecommitdiff
path: root/beam_tracing/python/colorGradient.py
blob: dd9c856148d94ed83c2af35c744d9cfcc108b3c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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