xxxxxxxxxx
27
let vecLocation;
let vecVelocity;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
vecLocation = createVector(width/2, height/2);
vecVelocity = createVector(random(-10, 10), random(-10, 10));
}
function draw() {
background(0);
fill(31, 127, 255);
noStroke();
ellipse(vecLocation.x, vecLocation.y, 20, 20);
vecLocation.add(vecVelocity);
if (vecLocation.x < 0 || vecLocation.x > width) {
vecVelocity.x = vecVelocity.x * -1;
}
if(vecLocation.y < 0 || vecLocation.y > height) {
vecVelocity.y = vecVelocity.y * -1;
}
}