How to adapt a library for Instance Mode (P5JS)

Not some library, but separate class files, which request the sketch’s p5 instance reference as their 1st argument:
https://github.com/GoSubRoutine/Ball-in-the-Chamber/tree/master/instance/classes

Both classes Ball & Chamber store the sketch’s reference in their property p:
https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/2.0.5/instance/classes/ball.js#L2-L10
https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/2.0.5/instance/classes/chamber.js#L2-L8

And then, access p5js’ API via that property p:
https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/2.0.5/instance/classes/ball.js#L31-L34
https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/2.0.5/instance/classes/chamber.js#L9-L12

See that instance mode sketch in action at the link below:
GoSubRoutine.GitHub.io/Ball-in-the-Chamber/instance/

1 Like