import colorsys
import struct
## e.g. gradient_color("#ff0000", 0.66, 0.91) #=> "#e84e4e"
def gradient_color(color, saturation_ratio, brightness_ratio):
rgb0 = struct.unpack('BBB', color[1:].decode('hex'))
h, s, v = colorsys.rgb_to_hsv(*[x / 255.0 for x in rgb0])
rgb1 = colorsys.hsv_to_rgb(h, s * saturation_ratio, v * brightness_ratio)
return "#" + struct.pack('BBB', *[x * 255 for x in rgb1]).encode('hex')