xxxxxxxxxx
21
/* the current sketch shows a ball that moves to the right, and gets sent back to the left of the screen when x reaches 350. Change the sketch so that the ball would bounce back and forth like the example gif
*/
let speed= 1;
let x = 50;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
ellipse(x, 200, 100, 100);
x=x+speed;
if (x > 350) {
speed=-1;
} else if (x ==50){
speed=1;
}
}