Determine font color based on background color?

I encountered similar problem. I had to find a good method of selecting contrastive font color to display text labels on colorscales/heatmaps. It had to be universal method and generated color had to be "good looking", which means that simple generating complementary color was not good solution - sometimes it generated strange, very intensive colors that were hard to watch and read.

I encountered similar problem. I had to find a good method of selecting contrastive font color to display text labels on colorscales/heatmaps. It had to be universal method and generated color had to be "good looking", which means that simple generating complementary color was not good solution - sometimes it generated strange, very intensive colors that were hard to watch and read.

After long hours of testing and trying to solve this problem, I found out that the best solution is to select white font for "dark" colors, and black font for "bright" colors. Here's an example of function I am using in C#: Color ContrastColor(Color color) { int d = 0; // Counting the perceptive luminance - human eye favors green color... double a = 1 - ( 0.299 * color. R + 0.587 * color.

G + 0.114 * color. B)/255; if (a Edit Changed the formula of counting a to "perceptive luminance" - it really looks better! Already implemented it in my software, looks great.

1 It's probably not important, but you might want a better function to compute the brightness stackoverflow. Com/questions/596216/… – Josh Lee Dec 6 '09 at 17:23 1 Thanks! Very useful (+1).

– Gacek Dec 6 '09 at 17:34 This looks like it'll be perfect. – Joseph Daigle Dec 6 '09 at 20:10 Improved the code - now it's even better – Gacek Dec 6 '09 at 20:24 Thanks a lot! Very helpful!

– Alex Hart Dec 6 '097 at 21:00.

Take a look at this Question here. It calculates the complementary color of any given color. This should do the trick for you.

Best wishes, Fabin.

2 That won't really be pleasant too look at. Yellow on purple, etc. Etc.. Eww! – Macke Dec 6 '09 at 17:12 You're definetely right with that point.

Gacek's solution is smarter. – halfdan Dec 6 '09 at 17:13.

If you're manipulating color spaces for visual effect it's generally easier to work in HSL (Hue Separation and Lightness) than RGB. Moving colours in RGB to give naturally pleasing effects tends to be quite conceptually difficult, whereas converting into HSL, manipulating there, then converting back out again is more intuitive in concept and invariably gives better looking results. Wikipedia has a good introduction to HSL and the closely related HSV.

And there's free code around the net to do the conversion (for example here is a javascript implementation) What precise transformation you use is a matter of taste, but personally I'd have thought reversing the Hue and Lightness components would be certain to generate a good high contrast colour as a first approximation, but you easily go for more subtle effects.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions