xxxxxxxxxx
22
class EVector {
constructor(x, y, Fx=0, Fy=0) {
this.pos = createVector(x,y);
this.resetForce();
}
resetForce() {
this.F = createVector(0,0);
}
updateForce(newF) {
this.F.add(newF);
}
display(field) {
let color = map(this.F.magSq(), 0, field.length, 40, 255);
stroke(0,40+color,40+color);
strokeWeight(2);
this.F.normalize();
this.F.mult(3);
line(this.pos.x, this.pos.y, this.pos.x+this.F.x, this.pos.y+this.F.y);
circle(this.pos.x+this.F.x, this.pos.y+this.F.y, 1);
}
}