processing / processing/p5.js

Allow p5 classes (like `p5.Color`, `p5.Vector` etc.) to be used outside of the browser (node, deno, bun etc.)?

Open
#6,830 14 comments 1 reaction 1 assignee View on GitHub

@limzykenneth is already working on this.

Since Jun 18, 2024.

Discussion p5.js 2.0+
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Topic

Hi, I'm building a multiplayer game using p5js. I would like to use the same classes for vectors and colors etc (like p5.Color, p5.Vector) on the server-side as on the frondend, but when I include them like this:

import { Color, Vector } from "p5";

I get the following error:

ReferenceError: Can't find variable: window
      at /home/robin/projects/102/node_modules/p5/lib/p5.min.js:2:541617
      at a (/home/robin/projects/102/node_modules/p5/lib/p5.min.js:2:513)
      at /home/robin/projects/102/node_modules/p5/lib/p5.min.js:2:555
      at /home/robin/projects/102/node_modules/p5/lib/p5.min.js:2:458110

I'm starting the server like this:

bun run src/server/main.ts

I think it would be cool to be able to use the classes that don't necessarily need the browser/canvas outside on other places too.

Maybe I'm just really dum and this is already possible? I also completely understand if this is out of scope for p5js, but I thought I'd ask :)

I can also split these classes into a seperate library/NPM package.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.