//tried my best but there seems to be an error(s). Stuck on the freezing ball theorem.
int x=300;
int speed=2;
boolean button=false;
void setup(){
size(600,600);
}
void draw(){
background(mouseX,mouseY);
noStroke();
if (button) {
x=x;
}
fill(mouseX,121,30);
rect(x,200,100,100);
if(x > width) {
speed=speed * -1;
}
else if (x < 0){
speed = speed * -1;
}
x = x+speed;
}
fill(255);
rect(x,200,100,100);
if(mousePressed) {
fill(8,34,255);
rect(x,300,100,100);
button=!button;
}else{
background(255);
fill(0);
rect(x,200,150,150);
}