tags:

views:

4

answers:

0

I have a randomly colored background that is split into different but solid colored rectangles. I want to draw a grid over the rectangles(which I can do easy and not the problem). The issue is because of the random colors I cannot hard code the grid color because it may not show up.

Another way to think about this is plotting a grid on a plot of a surface f(x,y). If the grid color happens to be the same color of the function(how every it is defined) then it won't be visible.

I would like to take the background color and compute a new color(either grayscale or similar to the background color) that is contrasted with the color so it can easily be seen(but not distracting such as pure white on pure black).

I've tried using the luminance and weighted luminance but it doesn't work well for all colors. I've also tried gamma correcting the colors but it also does not work well.

I would also like the grid color be as uniform as possible (I could possibly compute the adjacent grid colors to blend in). It is not that important but would be nice to have some uniformity.

The code I'm working with is based around

//byte I = (byte)(0.2*R + 0.7*G + 0.1*B); //byte I = (byte)(R + G + B)/3.0); byte I = (byte)(Math.Max(Bar.Background.R, Math.Max(Bar.Background.G, Bar.Background.B)));

if (I < 120) I = (byte)(I + 30); else I = (byte)(I - 30); //I = (byte)(Math.Pow(I/255.0, 1/2.0)*255);

I've also tried gamma correcting the rgb's first.

Anyone have any ideas?