We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › fading on white background
Page Index Toggle Pages: 1
fading on white background (Read 524 times)
fading on white background
Jan 4th, 2008, 3:27pm
 
Hi all,

i'm just try some examples on "fading", here is the code
Code:

void setup() {
size(200,200);
background(255);
}

void draw() {
fill(255,10);
rect(0,0,width,height);

stroke(0);
line(pmouseX,pmouseY,mouseX,mouseY);
}


with a white background i have "ghosts",
lines fades until they hit a "ligth gray",
then never disappear ...

only if my background is black or gray (with a white stroke)
i don't have problems

there is a solution?
Re: fading on white background
Reply #1 - Jan 5th, 2008, 4:54am
 
This is a very tough problem to solve with integer math, and it's built into the alpha-blending equations.  It gets progressively harder to add 10/255's of the difference with white and make "pure" white.  (in fact, it can't be done, even with infinite precision, it would still take an infinite number of steps to even approach it - sort of like Zeno's paradox)

What happens is eventually the difference between the two colors is so small that integer rounding errors lose the additional alpha blend, so your fade gets "stuck".  (btw, it'll also get stuck fading to black, it's just harder to see due to the gamma curve)

Exactly where it gets stuck is a factor of your alpha value.  With larger alpha it'll get closer to rgb 255 (or zero), but the problem will never entirely go away.

Essentially, something like this is going on:

rgb = 243 + (((255-243)*10)/256 = 243.46...
which when truncated to integer is 243, repeat as many times as you like, no effect -- you're now stuck.

The only sort of workaround is to write your own pixel-by-pixel manipulation routine that looks for values at the stuck value and increments them by one closer to the target value, FORCING them towards white.
Re: fading on white background
Reply #2 - Jan 5th, 2008, 7:33pm
 
thanks for the explanation
Page Index Toggle Pages: 1