xxxxxxxxxx
22
function setup() {
createCanvas(400, 400);
}
let xPos = 0;
let xSpeed = 4;
let xDir = 1;
let cRadius = 30;
function draw() {
background(220, 0, 120);
ellipse(xPos, height / 2, 2 * cRadius);
xPos = xPos + xDir * xSpeed;
if (xPos > width - cRadius) {
xDir = -1;
} else if (xPos < cRadius) {
xDir = 1;
}
}