import colorsys


def darker_color(c, amount=0.3):
    """Given HTML-style #RRGGBB color string, return variant that is
    darker by the given amount."""


    if c and c[0] == '#':
        c = c[1:]
    if len(c) != 6:
        raise ValueError
    r, g, b = map(lambda h: int(h, 16)/255., [c[0:2],c[2:4],c[4:6]])
    h, s, v = colorsys.rgb_to_hsv(r, g, b)
    v *= 1.0-amount
    r, g, b = [255*x for x in colorsys.hsv_to_rgb(h, s, v)]
    return '#%02x%02x%02x' % (r, g, b)