def rgba2hex(rgba):
    """ Convert rgba tuple (e.g. (0.5, 0.4, 0.2, 1.0)) to hex code """
    hx = ''
    for f in rgba[:3]:
        s = hex(int(f*255))[2:]
        if len(s)<2:
            s = '0'+s
        hx += s
    return "#"+hx