November 8, 2013
MarkBernstein.org
 
Follow me on Twitter

Choosing Colors

In Tinderbox maps, we often need to choose a sensible text color for a note based on the note’s background color.

Choosing Colors

Problem: Given a color’s RGB or HSV values, choose whether black or white text is more suitable.

Choosing Colors

Note that simply looking at brightness won’t suffice. Here’s are two colors that have 100% brightness. Clearly, white needs black text, but blue appears to want white text.

The solution must be well known, but I don’t know it. Do you? Email me.

UPDATE: Ed Blachman finds the answer, nicely explained by Nir Dobovizki.

sqrt( .241 r^2 + .691 g^2 + .068 b^2 )> 0.5

where r,g, and b are the color components on a scale of 0-1. In essence, this measures the distance from black in RGB space, weighting each color for the sensitivity of the eye.