> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.WYRewtuyplF/rev.768
 * 
 * authors: 
 *   Bruno Buccolo

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// Pressing Control-R will render this sketch.

Ghost[] haunted = new Ghost[100];
int fear = 1;

void setup() {  // this is run once.   
    
    background(0);
    size(400, 400); 
      
    smooth();
    frameRate(30);
    
    for (var i = 0; i < 100; i++){
        haunted[i] = new Ghost();
    }

} 

void draw() {  // this is run repeatedly.  
    if (fear) { 
        background(0); 
    } else {
        for (var i = 0; i < 100; i++){
            haunted[i].draw();
        }
    }
    
}

class Ghost {
    int x, y, sizex, sizey, opacity;
    float vx, vy;
    
    
    Ghost(){
        this.sizex = random(75);
        this.sizey = random(75);
        
        this.opacity = random(100);
        
        this.x = 200;
        this.y = 200;
        
        this.vx = (random(20)-10)*2;
        this.vy = (random(20)-10)*2;
        
    }
    
    void draw(){
        
        noStroke();
        rect(x, y, sizex, sizey);
        fill(mouseX, mouseY, mouseX - mouseY, opacity);
        
        x += vx;
        y += vy;
        
        vx = (x < 0 || x > 400-sizex) ? -vx : vx;
        vy = (y < 0 || y > 400-sizey) ? -vy : vy;
        
        
    }
}
        
         
void mousePressed() {
    fear = 0;
}

void mouseReleased() {
    fear = 1;
}