How to use export & import in p5.js

Nope! In global mode its instance reference is stored in p5.instance static property:

export default class Ball {
  constructor(world, p = p5.instance) {
    this.world = world;
    this.vel = (this.p = p).createVector();
    this.body = this.c = null;
    this.respawn();
  }

My both online module examples use p5.js’ global mode.

The “Matter.js Bouncing Colorful Balls” is also available in p5js’ instance mode.

1 Like