Example 1: Single Ball Bounce
Code
let x = 200;
let y = 200;
let vx = 3;
let vy = 2.5;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(250);
x += vx;
y += vy;
if (x < 20 || x > width - 20) vx *= -1;
if (y < 20 || y > height - 20) vy *= -1;
fill(255, 48, 145);
noStroke();
circle(x, y, 40);
}Try this: Dampen velocity a little each bounce to simulate friction.