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 to white with cumulative alpha
Page Index Toggle Pages: 1
fading to white with cumulative alpha (Read 446 times)
fading to white with cumulative alpha
Jun 5th, 2007, 6:57am
 
hi.  

i am drawing lines to the screen based on camera input and fading them by drawing a rectangle the same size as my sketch with an alpha value (say, 15).  this does not however, seem to be getting me back to white (255, 255, 255, 100 [presumably]), and instead the lines "fade" to a barely there dull gray.  

here is a a little test file that shows the same problem as my code:   

// test_fade
int fadeAlpha = 15;
int lineAlpha = 70;

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

void draw() {
 //print("FADE ALPHA:  " + fadeAlpha +'\n');
 noStroke();
 fill(255,255,255, fadeAlpha);
 rect(0,0,200,200);
 stroke(0,0,155, lineAlpha);
 
 if(mousePressed) {
   line(mouseX, mouseY, pmouseX, pmouseY);
 }
 
 if(keyPressed) {
   if(key =='u'){
     fadeAlpha = fadeAlpha+1;
   }
   if(fadeAlpha >100){
     fadeAlpha = 100;
   }

   if(key == 'd'){
     fadeAlpha = fadeAlpha-1;
   }
   if(fadeAlpha <= 0){
     fadeAlpha = 0;
   }
 }
}

does anyone know why this doesn't work to fade the background to white?  or how i can change it to fade to white?  
Re: fading to white with cumulative alpha
Reply #1 - Jun 5th, 2007, 7:52am
 
you might be able to do something with this
Code:

//fade
float alp = 0; // holder for the alpha
float Control = 30; // the lower this is the faster it fades

void setup()
{
size(200,200);
background(0,0,0);
noStroke();
}

void draw()
{
if(alp < 255){
alp += ((255-alp)/Control);
if(alp > 254.5){
alp = 255;
}
}
fill(255,255,255,alp);
rect(0,0,width,height);
if(alp == 255 && keyPressed){
background(0);
alp = 0;
}

}
Page Index Toggle Pages: 1