I would like to fade the color of a pixel out toward white, but obviously maintain the same color. If I have a pixel (200,120,40)
, will adding 10 to each value to m
The question, "to fade the color of a pixel out toward white" (not some shade of gray), is really about mixing the original pixel color with white, going from 100% original color and 0% white to 0% original color and 100% white. There's not more to it. Doing this in, for example, 101 steps would look like this:
r0= 200; // as in the question
g0= 120;
b0= 40;
for(i= 100; i >= 0; i--){
r= (i * r0 + (100 - i) * 255) / 100;
g= (i * g0 + (100 - i) * 255) / 100;
b= (i * b0 + (100 - i) * 255) / 100;
// use this color (r, g, b) somehow
}