Converting my Processing code to p5.js (ArrayList + others!)

That’s not how we define classes’ constructor, methods & fields under JS syntax!
You should read the JS reference for it:

Also, there’s no ArrayList either. We use JS arrays instead:

And while in Java we can generally omit the keyword this before accessing a class member, in JS it’s mandatory:

Now w/ all the info above, here’s a partial but proper JS conversion of your class ParticleSystem:

class ParticleSystem {
  constructor(position) {
    this.origin = position.copy();
    this.particles = [];
  }
 
  addParticle() {
    this.particles.push(new Particle(this.origin));
  }

  // ...
}
4 Likes