Skip to content

Instantly share code, notes, and snippets.

@dipamsen
Last active February 14, 2021 09:04
Show Gist options
  • Save dipamsen/ccf46106d311bb7dd93fea40c634eece to your computer and use it in GitHub Desktop.
Save dipamsen/ccf46106d311bb7dd93fea40c634eece to your computer and use it in GitHub Desktop.

Using p5.js in Node - all "window" variables used by p5

These are the mandatory window properties accessed by p5.js on import, and what can be used instead:

window.requestAnimationFrame

By default, there is no requestAnimationFrame in node. p5 has a polyfill for requestAnimationFrame for older browsers, so we don't need to implement anything.

window.setTimeout = global.setTimeout

window.devicePixelRatio = 1

window.performance (MDN)

Use node core module perf_hooks

window.document = JSDOM document

window.screen (MDN)

p5 uses screen.width and screen.height for displayWidth and displayHeight (Not required while working in node, so using null)

window.navigator (MDN)

p5 uses navigator.mediaDevices.getUserMedia() which is used to access the user mic and camera feed. (Not required while working in node)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment