npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

game-of-life-p5js

v1.0.0

Published

Conway's Game of Life and B/S cellular automata for p5.js

Readme

game-of-life-p5js

Run Conway's Game of Life (and its B/S relatives like HighLife) on a p5.js canvas. The grid wraps around its edges, so gliders fly off one side and reappear on the other.

The drawing helper takes a p5 instance as its first argument, so the package works in instance mode (and global mode too). The grid model and the step rule are pure and decoupled from p5, so the whole simulation can be used and tested without a canvas.

Installation

npm install game-of-life-p5js

p5 is a peer dependency (^1.0.0); install it alongside if you haven't already:

npm install p5

Usage (instance mode)

const p5 = require('p5');
const { randomGrid, step, drawGrid } = require('game-of-life-p5js');

new p5((p) => {
    const cell = 8;
    let grid;

    p.setup = () => {
        p.createCanvas(640, 480);
        p.frameRate(12);
        grid = randomGrid(p.width / cell, p.height / cell, 0.3, () => p.random());
    };

    p.draw = () => {
        p.background(10);
        p.fill(0, 255, 140);
        drawGrid(p, grid, cell);
        grid = step(grid); // advance one generation
    };
});

Run a variant by passing a different B/S rule:

const { step, parseRule } = require('game-of-life-p5js');

grid = step(grid, parseRule('B36/S23')); // HighLife (self-replicating patterns)

API

randomGrid(cols, rows, density = 0.3, randomFn = Math.random)

Builds a rows × cols grid seeded randomly. randomFn returns [0, 1); pass () => p.random() to share p5's RNG.

step(grid, rule = { birth: [3], survival: [2, 3] })

Advances the grid one generation and returns a fresh grid (the input is never mutated). The default rule is Conway's Life (B3/S23).

parseRule(rulestring)

Parses a rulestring like "B3/S23" or "B36/S23" into { birth, survival } arrays.

drawGrid(p, grid, cellSize = 10)

Draws the live cells as filled squares. The background and fill colour are left to the caller, so fades and trails are possible.

Pure helpers (no p5 needed)

  • createGrid(cols, rows, fill = 0) — an empty rows × cols grid.
  • countNeighbors(grid, x, y) — live neighbours in the wrapped 8-neighbourhood.
const { createGrid, step } = require('game-of-life-p5js');

let grid = createGrid(5, 5);
grid[2][1] = grid[2][2] = grid[2][3] = 1; // a blinker
grid = step(grid); // now vertical

License

MIT © Damian Sire