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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@planet-lodder/game-of-life

v0.0.7

Published

Game-of-life implemented as a HTML web component.

Downloads

1

Readme

Conways Game of Life

A JavaScript implementation of Conway's Game of Life.

Features

The main features included in this package:

  • A <game-of-life> web component, that you can embed in your own website
  • Configurable game settings, including a way to load a preset from an image
  • Styled using Tailwind CSS, so look and feel can be easily customized
  • Multiple view types can be selected, each implemented as a web component
  • The GameEngine can be extended or replaced using GameEngineCore.

View types that are currently included:

  • html - A simple view using DIV's to paint cells (uses shadow DOM)
  • svg - View is generated as a SVG image (uses shadow DOM)
  • canvas - Draw the view directly onto an image canvas
  • webgl - Game is rendered as polygons in a WebGL context
  • benchmark - A special view type to measure game engine performance

Each view type has it's strengths and weaknesses, for example html and svg performs really well (using the shadow DOM) for smaller game sizes, where as canvas and webgl generally performs better for large and complex games.

By supporting multiple GameEngine's and view types, we can benchmark and compare their performance, given small and very large workloads.

Installation

You can install the npm package into your local project using:

npm i @planet-lodder/game-of-life

Then import the game code and all its dependencies:

// Import the custom web component and register in DOM
import "@planet-lodder/game-of-life/web-component";

Alternatively, you can just embed the minimized javascript file directly into your project or website, using web-component.js.

Usage

Include the required javascript, then you can declare the board game like so:

<script src="/js/web-component.js"></script>

<game-of-life
  title="Demo of Life"
  image="/presets/simple/traffic-circle.gif"
  width="100"
  height="100"
  scale="10"
  delay="0"
  view="svg"
></game-board>

If you want to customize or extend the game logic, you can also use module imports:

import { GameEngineCore, BenchmarkRenderer } from "@planet-lodder/game-of-life"

export class GameEngine extends GameEngineCore {

  load(data) {
    this.data = data;
    if (this.view) this.view.createView(this, data)
  }

  tick() {
    let data = this.data;
    ...
  }
}

// Add view as a new DOM element
let view = new BenchmarkRenderer()
document.body.appendChild(view)

// Attach view to custom game engine and start
let config = {
  image: '/presets/basic/101.gif'
}
let engine = new GameEngine(config, view);
engine.start()

Configuration

The following settings are available:

| Setting | Description and defaults | | ------- | ----------------------------------------------------------------------------- | | title | Optional title for the toolbar (default: "Game of Life"). | | image | The image containing the preset to load on the board. | | width | The horizontal number of cells on the board. Defaults to image size. | | height | The vertical number of cells on the board. Defaults to image size. | | scale | The scale can be used to magnify the view. | | delay | If specified, limits the frame rate by with some delay (in millisecons). | | wrapped | If set to true, the board wraps around both the x and y axis. | | view | Specify the view type. Options: html, svg, canvas, webgl, benchmark | | start | If set to true, will auto start the game once loaded. |

Local development with web-dev-server

You can download the source code locally and run it in development mode:

git clone [email protected]:planet-lodder/conways-game-of-life.git
cd conways-game-of-life

npm install
npm start

This runs a local development server that serves the game as a web component, located in static/index.html