xxxxxxxxxx
23
let x = 0;
let xspeed = 10;
function setup() {
createCanvas(600, 600);
}
function draw() {
background(20);
// draw an ellipse in the middle of the left edge of the canvas
// make the ellipse move to the right side of the canvas
// when the ellipse reaches the right side of the canvas,
// it turns around and move back to the left side of the canvas
// when it reaches the left edge of the canvas,
// it turns around the move toward the right side of the canvas
// forever
ellipse(x, height / 2, 20);
x += xspeed;
if (x > width || x < 0) {
xspeed = xspeed * -1;
}
}