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