"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Although colors chosen by your method may contrast, they might still be unreadable. Have you ever seen a webpage with a pure blue background and pure yellow text? Perhaps a more eye-friendly method is to always use black or white foreground text, which would hardly clash with anything
To determine whether white or black would contrast more with your random background color, you can use the luminosity (brightness) of the background color. The luminosity is the value the color would become when converted to grayscale. What's nice is that human perception is built in -- the formula for luminosity takes into account the differences in how red, green, and blue contribute to the perception of "brightness". If the luminosity is brighter than 50% gray, use black text, otherwise use white text. The results are very readable.
Update: (This is for my own reference in the future as much as anything, so I can find these links when I need to.) To be nitpicky, choosing a "random" color by uniformly choosing random RGB components is not as random as one would think. RGB is not a perceptually uniform color space. A better method to generate colors that are perceptually random instead of numerically random in their RGB components would be to use a different color space like L*a*b* or L*u*v*, where the three color dimensions are closer to perceptually uniform. Uniformly select the three components in this color space, then convert to RGB. For more info, see the Color Space FAQ, questions C-35 and C-39. But for the purposes of pg's app, uniformly choosing in RGB-space is probably quite sufficient, as we only need the color to be noticably different than the previous. blokhead In reply to Re: to generate a set of well contrasted colors
by blokhead
|
|