xxxxxxxxxx
37
let position;
let vector;
class mover {
constructor() {
this.position = createVector(1, 1);
this.vector = createVector(1, 1);
}
display() {
ellipse(this.position.x, this.position.y, 10, 10);
}
checkEdges() {
if (this.position.x > width || this.position.x < 0) {
this.vector.x *= -1;
}
if (this.position.y > height || this.position.y < 0) {
this.vector.y *= -1;
}
}
update() {
this.position.add(this.vector);
}
}
function setup() {
createCanvas(400, 400);
ball = new mover();
}
function draw() {
background(220);
ball.checkEdges();
ball.update();
ball.display();
}