xxxxxxxxxx
22
let x, y, xLeft, xRight, yUp, yDown;
let xSpeed = 1;
let ySpeed;
function setup() {
createCanvas(500, 400);
x = width / 2;
y = height / 2;
ySpeed = (height / width) * xSpeed;
}
function draw() {
background(220);
ellipse(x, y, 50, 50);
if (x < mouseX) x += xSpeed;
if (x > mouseX) x -= xSpeed;
if (y < mouseY) y += ySpeed;
if (y > mouseY) y -= ySpeed;
}