Currently, I am diving into the world of p5 with the help of Coding train, but I have chosen to implement everything within a Typescript/webpack project.
In my code, I am utilizing p5 as an instance, and everything seems to be functioning correctly. However, I have a nagging suspicion that I might be making a mistake somewhere.
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);
}
One aspect that is perplexing me is the fact that I am importing P5 specifically for its Vector properties, yet when it comes time to instantiate a vector, I need to pass P5 to the constructor from the index file.
particles[i] = new Particlehelper(p);
This method feels redundant - it seems like I am essentially calling upon P5 twice. Despite my efforts, I cannot seem to figure out how to solely utilize the imported p5 object within the class.
Additionally, the notation of "public constructor" is unfamiliar to me. My linter prompted me to include it, but I am unsure if this is the correct approach or not.
Any insights would be greatly appreciated.