xxxxxxxxxx
27
/* 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 > 350) {
//x = 50;
speed = -speed;
}
else if(x<50){
speed = -speed;
}
}