xxxxxxxxxx
31
let position;
let velocity;
// let x = 10;
// let y = 100;
// let directionX = 2;
// let directionY = 3;
function setup() {
createCanvas(400, 400);
position = createVector(10, 100);
velocity = createVector(2, 3);
}
function draw() {
background(220);
fill(255, 200, 5);
ellipse(position.x, position.y, 25, 25);
// position.x = position.x + velocity.x;
// position.y = position.y + velocity.y;
position.add(velocity);
if (position.x > width || position.x < 0){
velocity.x *= -1;
}
if (position.y > height || position.y < 0){
velocity.y *= -1;
}
}