xxxxxxxxxx
38
let x = 300;
let y = 200;
let xspeed = 4;
let yspeed = -3;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(0);
move();
bounce();
display();
}
function bounce() {
if (x > width || x < 0) {
xspeed = xspeed * -1;
}
if (y > height || y < 0) {
yspeed = yspeed * -1;
}
}
function display() {
stroke(255);
strokeWeight(4);
fill(200, 0, 200);
ellipse(x, y, 24, 24);
}
function move() {
x = x + xspeed;
y = y + yspeed;
}