xxxxxxxxxx
27
let x;
let xspeed=1;
function setup() {
createCanvas(400, 400);
x= width/2
}
function draw() {
background(220);
//if you are outside of the boundary, turn around. right now we have hitting the boundary
if (x > width || x<0) {
xspeed+= -5;
//move left
//turn around to go left
//move right
//turn around to go right
}
//move
//x speed can either be +1 or -1
x= x+ xspeed
ellipse(x, 200, 20, 20);
}