xxxxxxxxxx
// simple bouncing ball - version 1
let width = 500;
let height = 300;
r = 20; // radius of the ball
// initial position of ball
x = 100;
y = 100;
speed = 0; // default speed
// direction of motion
dx = speed;
dy = speed;
function setup() {
const canvas = createCanvas(width, height);
}
function draw() {
background(240);
x += dx;
y += dy;
if ((x > width-r) || (x < r)) {
dx = dx * -1;
}
if ((y > height-r) || (y < r)) {
dy = dy * -1;
}
fill('blue');
circle(x, y, r*2);
}