Skip to content

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

Closed
@RobinBoers

Description

@RobinBoers

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions