xxxxxxxxxx
26
/* 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 x = 50;
let speed = 1
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
ellipse(x, 200, 100, 100);
x = x + speed;
if (x > width - 50) {
speed = -1;
} else if (x==50){
speed = 1;
}
}