I'm learning some p5 stuff from Coding train, but I'm writing everything in Typescript/webpack project.
I am using p5 as an instance, and my code works fine, but I have a feeling that I'm doing something wrong.
import * as p5 from 'p5';
export class Particlehelper {
private pos: p5.Vector;
private vel: p5.Vector;
private accl: p5.Vector;
public constructor(p: p5) {
this.pos = p.createVector(p.random(p.windowWidth), p.random(p.windowHeight));
// this.vel = p.createVector(0, 0);
this.vel = p5.Vector.random2D();
this.accl = p.createVector(0, 0);
}
What confuses me here is - I'm importing P5 as I need class properties to be of type Vector, but then in order to instanciate vector, I'm passing P5 to the constructor from index file.
particles[i] = new Particlehelper(p);
I have a feeling that is wrong - it sounds to me like I'm doing the same thing twice, but I could not untangle how to use just imported p5 within the class.
As well - I've never seen "public constructor" notation, but linter forced me to add it there - not sure if that is OK or not?
Thanks,