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

@ismailnguyen/game-of-life-js

v1.0.3

Published

Conway's Game of Life - A simple JavaScript package for embedding Game of Life visualization in any website

Readme

game-of-life-js

Conway's Game of Life - A simple JavaScript package for embedding Game of Life visualization in any website.

npm version License: MIT

Features

  • 🎮 Easy to use: Simple API with sensible defaults
  • 🎨 Customizable: Configure colors, speed, grid size, and initial patterns
  • 🚀 Auto-start: Begins automatically or on demand
  • 🎯 Lightweight: No dependencies, pure JavaScript
  • 📱 Responsive: Works on desktop and mobile
  • 🔧 Interactive: Built-in controls for start/stop/reset

Installation

npm install @ismailnguyen/game-of-life-js

Or include directly in your HTML:

<script src="https://unpkg.com/@ismailnguyen/game-of-life-js/src/game-of-life.js"></script>

Usage

GameOfLife.create('game-container');

Quick Start

HTML

<!DOCTYPE html>
<html>
<head>
    <title>Game of Life Demo</title>
</head>
<body>
    <div id="game-container"></div>
    
    <script src="https://unpkg.com/@ismailnguyen/game-of-life-js/src/game-of-life.js"></script>
    <script>
        // Simple usage with defaults
        GameOfLife.create('game-container');
    </script>
</body>
</html>

Node.js / ES6 Modules

const GameOfLife = require('game-of-life-js');

// Create game instance
const game = GameOfLife.create(document.getElementById('my-container'));

API Reference

GameOfLife.create(container, options)

Creates a new Game of Life instance in the specified container.

Parameters

  • container: HTMLElement | string - The DOM element or element ID where the game will be rendered
  • options: Object - Configuration options (optional)

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | width | number | 800 | Canvas width in pixels | | height | number | 600 | Canvas height in pixels | | cellSize | number | 10 | Size of each cell in pixels | | speed | number | 100 | Animation speed (milliseconds between generations) | | autoStart | boolean | true | Whether to start the game automatically | | initialPattern | string|Array | 'random' | Initial pattern ('random', 'glider', 'blinker', or custom array) | | fillColor | string | '#000000' | Color for live cells | | backgroundColor | string | '#ffffff' | Canvas background color | | borderColor | string | '#cccccc' | Border color |

Returns

Returns a GameOfLife instance with the following methods:

  • start() - Start the animation
  • stop() - Stop the animation
  • toggle() - Toggle between start/stop
  • reset() - Reset to initial state

Examples

Basic Usage

// Minimal setup with defaults
GameOfLife.create('game-div');

Custom Configuration

GameOfLife.create('game-div', {
    width: 600,
    height: 400,
    cellSize: 8,
    speed: 150,
    fillColor: '#ff6b6b',
    backgroundColor: '#f8f9fa',
    initialPattern: 'glider'
});

Manual Control

const game = GameOfLife.create('game-div', {
    autoStart: false  // Don't start automatically
});

// Control manually
game.start();   // Start the game
game.stop();    // Stop the game
game.reset();   // Reset to initial state

Custom Initial Patterns

// Define a custom pattern (beacon oscillator)
const customPattern = [
    [1, 1, 0, 0],
    [1, 0, 0, 0],
    [0, 0, 0, 1],
    [0, 0, 1, 1]
];

GameOfLife.create('game-div', {
    initialPattern: customPattern,
    cellSize: 15
});

Built-in Patterns

Available built-in patterns:

  • 'random' - Random distribution of live cells
  • 'glider' - Classic glider pattern
  • 'blinker' - Simple oscillating pattern

Conway's Game of Life Rules

The Game of Life follows these simple rules:

  1. Birth: A dead cell with exactly 3 live neighbors becomes alive
  2. Survival: A live cell with 2 or 3 live neighbors stays alive
  3. Death: All other live cells die (underpopulation or overpopulation)

Browser Support

This package works in all modern browsers that support:

  • HTML5 Canvas
  • ES5 JavaScript

Development

# Clone the repository
git clone https://github.com/ismailnguyen/game-of-life-js.git

# Navigate to directory
cd game-of-life-js

# Open example.html in your browser to see the demo

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About Conway's Game of Life

Conway's Game of Life is a cellular automaton devised by mathematician John Horton Conway in 1970. It's a zero-player game, meaning its evolution is determined by its initial state, requiring no further input. Despite its simple rules, the Game of Life is Turing complete and can simulate any computer algorithm.