xxxxxxxxxx
78
let point1;
let point2;
let point3;
function setup() {
createCanvas(400, 400);
point1 = new Follow(random(0, width), random(0, height));
point2 = new Follow2(random(0, width), random(0, height));
point3 = new Follow3(50);
}
function draw() {
background(220);
fill(255);
point1.setPos(mouseX, mouseY);
point1.update();
point1.draw();
point2.setPos(mouseX, mouseY);
point2.update();
point2.draw();
point3.setPos(mouseX, mouseY);
point3.update();
point3.draw();
}
class Follow {
constructor(x, y) {
this.currPos = createVector(x, y);
this.finalPos = createVector(x, y);
this.speed = random(0.1, .2);
}
setPos(x, y) {
this.finalPos.set(x, y);
}
update() {
this.currPos = p5.Vector.lerp(this.currPos, this.finalPos, this.speed);
}
draw(functionToDraw) {
// functionToDraw(this.currPos.x, this.currPos.y);
ellipse(this.currPos.x, this.currPos.y, 25, 25);
}
}
class Follow2 extends Follow {
draw() {
rect(this.currPos.x, this.currPos.y, 25, 25);
}
someOtherFunc() {
console.log('hi');
}
}
class Follow3 extends Follow {
constructor(length) {
super(random(0, width), random(0, height));
this.length = length;
}
draw() {
line(this.currPos.x, this.currPos.y, this.currPos.x + this.length, this.currPos.y+this.length);
}
someOtherFunc() {
console.log('hi');
}
}