How to spawn a rectangle when mouse is clicked (however many times you want) and make it do the same functions as my code can

Code:
float rectx,recty,xspeed=7,yspeed=7;

void setup() {
fullScreen();

}
void draw() {
background(0);
rect(rectx,recty,300,150);
fill(0,255,0);
if(mousePressed==true);
rect(recty,rectx,300,150);

if(sideCollision(rectx)) {
xspeed = xspeed * -1;
}
if(topOrBottomCollision(recty)) {
yspeed = yspeed*-1;
}
rectx = rectx + xspeed;
recty = recty + yspeed;
}

boolean sideCollision(float x) {
if(x<0 || x>width-300) {
return true;
} else {
return false;
}
}

boolean topOrBottomCollision(float y) {
if(y<0 || y>height-150) {
return true;
} else {
return false;
}
}

You can look at ArrayList in the reference and then for loop over the items to display and to manage them

You can have one ArrayList for x and one for y

Later you can use a class Ball