Thanx ! but i have done something a bit differerent, i have told processing to erase everything that was painted with this code :
Code: if (mousePressed==true)
background(#FA0058);
In my bouncing ball sketch http://www.tweakingknobs.com/63.html this is what i want.
But in the many bouncing rects i want it the other way round.
So, whith the many bouncing rects i want that is always not leaving trails, but when you click on it it leaves trails.
I have tried , but i cant make it, do you know how ?
Here's the code
Code:// many bouncing bal program
// global variables
int ballCount = 500;
int ballSize = 18;
int ballSpeed =3;
float []xspeed = new float [ballCount];
float []yspeed = new float [ballCount];
float []xpos = new float [ballCount];
float []ypos = new float [ballCount];
float []wdth = new float [ballCount];
float[]ht = new float [ballCount];
//initialize sketch
void setup(){
size (800,300);
background(#FA0058);
noStroke();
frameRate(30);
smooth();
//initialize values for all balls
for (int i=0; i<ballCount; i++) {
// set variable ball speed
xspeed[i] = random(1, ballSpeed);
yspeed[i] = random (-ballSpeed, ballSpeed);
//ball varied ball sizes
wdth[i] = random(1, ballSize);
ht[i] = wdth[i];
// set initial ball placement
xpos[i] = width/2+random(-width/3, width/3);
ypos[i] = height/2+random(-height/3, height/3);
}
}
// turnoff stroke
// draw
void draw(){
// updates background;
if (mousePressed==true)
background(#FA0058);
for(int i=0; i<ballCount; i++){
// fill(#FA0058,25);
//rect (width/2,height/2,width,height)
fill(255);
//drawballs
rect (xpos[i],ypos[i], wdth[i],ht[i]);
// upgrade ball pos
xpos[i]+=xspeed[i];
ypos[i]+=yspeed[i];
// conditionals
if (xpos[i]+wdth[i]/2>=width || xpos[i]<=wdth[i]/2){
xspeed[i]*=-1;
}
if (ypos[i]+ht[i]/2>=height || ypos[i]<=ht[i]/2){
yspeed[i]*=-1;
}
}
}