p5.js static functions in instance mode in observablehq

Hi everyone,

I am trying to use p5.js static functions in instance mode in observablehq following this example How to call static p5.Vector methods in instance mode - Processing 2.x and 3.x Forum .

This is my code: p5.js static functions on observablehq / Paulo Sobrinho / Observable

But when I uncomment the function subVec() I got an error “TypeError: Cannot read properties of undefined (reading ‘sub’)”.

Could you help me please?

Is there any more better or elegant way of using p5.js static functions in observablehq?

Thanks in advance,

You need to import both p5 (a wrapper/helper for Observable) and P5 (the actual library object) from Tom’s notebook:

import {p5, P5} from "@tmcw/p5"

Then you can call:

v3 = P5.Vector.sub(v1, v2);

Thank you so much!