PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Gradual graying

I'm sure this is simple, but... to gray an image, you simply average the R/G/B values and set all three to that average value. Easy enough.

However, it escapes me how to gradually gray out an image, ala WinXP when you click Shutdown and wait a few moments.

Could someone point out the obvious for me? Thanks!
Ok, im not sure about this, but couldnt you check what the average is and then have each value try to approach it by a set incriment each frame? Such as:

if(red<average)
{
red+=(average-red)/number of frames to grey out)
}

I dont know the algorithm off hand, but I know if you drop the "saturation" on any picture in photoshop it will eventually grey out just like in the windows shutdown. Maybe if you did a search on saturation you could fine the correct way to do this.
Thank DillRye, you put me on to the solution (well, I should say, one possible solution). As I expected, it was pretty obvious once you wrote it. For reference, what I did is this:

Code:

int greyFade = 0;
// Then, for each pixel plotted I call a function which contains the following...
// R, G, B are the input pixel's color components
int average = (R + G + B) / 3;
if (R < average ) {
if (R + greyFade < average) {
R = R + greyFade;
} else {
R = average;
}
} else {
if (R > average ) {
if (R - greyFade > average) {
R = R - greyFade;
} else {
R = average;
}
}
}
if (G < average ) {
if (G + greyFade < average) {
G = G + greyFade;
} else {
G = average;
}
} else {
if (G > average ) {
if (G - greyFade > average) {
G = G - greyFade;
} else {
G = average;
}
}
}
if (B < average ) {
if (B + greyFade < average) {
B = B + greyFade;
} else {
B = average;
}
} else {
if (B > average ) {
if (B - greyFade > average) {
B = B - greyFade;
} else {
B = average;
}
}
}
// Then I just do greyFade--; once per frame for 255 times (I guess I don't have to do it 255 frames really, but what the hell, I'll be absolutely certaian to hit the average for all pixels in that case)

I'm sure it's not the best algorithm ever written for this, but it seems to do what I want. Thanks for the help!