def color_to_str(C):
    """Convert color value to hex string."""
    # Scale from [0-1] to [0-255]
    V = [int(round(c * 255)) for c in C]

    # Clamp values to [0-255]
    for i in range(len(V)):
        V[i] = max(min(V[i], 255), 0)

    return '#{:02X}{:02X}{:02X}'.format(V[0], V[1], V[2])