I made the most basic of functions to try to decide based on a CSS color background, what color to use for text on the background so it's not lost ( only black or white). The one below, seems to work for quick and dirty uses. It's just fun. But I know a lot more can be done mathematically with the r,g,b components. I tried a few silly things with sliders to filter the CSS colours also. Anyway have a gist here.
The function that I did is below. Yes, it's crap, but it sort of works if you have nothing else. Maybe someone with time on their hands can come up with something more exacting.
def safe_color(css_color):
rgba = ui.parse_color(css_color)
r = rgba[0]
g = rgba[1]
b = rgba[2]
if (((r + g + b) / 3 ) > .55) :
return 'black'
else:
return 'white'

Output from gist