xxxxxxxxxx
32
let dia;
let x, y;
let xSpd, ySpd;
function setup() {
createCanvas(400, 400);
background(220);
dia = 30;
x = 250;
y = 250;
xSpd = random(-5, 5);
xSpd = random(-5, 5);
}
function draw() {
background(220); // comment out to see how the circle moves
x = x + xSpd;
y = y + ySpd;
// make it bounce
if(x<0 || x > width){
xSpd = xSpd * -1; // reverses movement direction when hitting edge of screen
}
if(y<0 || y > height){
ySpd = ySpd * -1;
}
circle(x, y, dia);
}