# p5-in-node

> Demo library for running p5.js sketches in node

Latest version **0.0.2** (published 2023-10-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install p5-in-node
pnpm add p5-in-node
yarn add p5-in-node
bun add p5-in-node
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2023-10-19 |
| First published | 2023-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dipam Sen |
| Maintainers | dipamsen |

## Links

- npm: https://www.npmjs.com/package/p5-in-node
- npm.io page: https://npm.io/package/p5-in-node

## Dependencies (2)

- [jsdom](https://npm.io/package/jsdom.md) ^22.1.0
- [canvas](https://npm.io/package/canvas.md) ^2.11.2

## Recent versions

- 0.0.2 (latest) — 2023-10-19
- 0.0.1 — 2023-10-19

## README

# p5 in node

Use p5.js inside Node!

## Installation

```bash
npm install p5-in-node p5
```

## Usage

Currently only supports instance mode so as to not pollute the global scope.

```js
import { runSketch, saveAsPNG } from "p5-in-node";

// Sketch function in instance mode
const sketch = (p) => {
  p.setup = () => {
    p.createCanvas(400, 400);
    p.noLoop();
  };

  p.draw = () => {
    p.background(51);
    p.fill(255);
    p.rect(100, 100, 200, 200);

    saveAsPNG(p, "sketch.png");
  };
};

runSketch(sketch, 400, 400);
```

Here, the sketch function receives the p5 instance as an argument, which can be used to define event functions, like `setup()` and `draw()`. Its API is the same as p5.js.

The library exports two functions - `runSketch()` and `saveAsPNG()`:

- `runSketch(sketchFn, w, h)`:
  - `sketchFn`: The p5 sketch function
  - `w`: width of the canvas
  - `h`: height of the canvas
- `saveAsPNG(pInst, filename)`
  - `pInst`: the p5 instance
  - `filename`: the filename to save the image as

---
_Source: https://npm.io/package/p5-in-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
