Timer Control for Fade In / Out
              in 
             Programming Questions 
              •  
              2 years ago    
            
 
           
             Hello to all,
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
              
           
 
            
           
             I am trying to create a sketch that does the following:
            
            
             1) In the first mouse click the shape fades in, and remains with full opacity
            
            
             2) In the second mouse click the shape fades out and remains with no opacity
            
            
             I have written the following code but there are a few problems with it. Also Im not sure if this is the right way to do this.
            
            
             Thank you for your help.
            
            - float fade = 0;
 - int passedTime = 0;
 - boolean boolFade = false;
 - void setup(){
 - size(200,200);
 - }
 - void draw(){
 - background(0);
 - rectFade();
 - }
 - void mousePressed(){
 - boolFade = !boolFade;
 - }
 - void rectFade(){
 - if (boolFade==true) {
 - passedTime = passedTime + 1;
 - if (passedTime > 0) {
 - fade = map(passedTime, 0, 20, 0, 255);
 - fill(255, fade);
 - rect (50,50,100,100);
 - }
 - } else {
 - passedTime = 0;
 - boolFade = !boolFade;
 - }
 - }
 
 
              
              1  
            
 
            