Skip to content

rankdim/conway

Repository files navigation

@rankdim/conway

A lightweight library for beautfiul game of life embeds.

Installation

$ npm i @rankdim/conway

User Guide

import { conway, patterns } from "@rankdim/conway";

const game = conway("conway-1", {
  cellSize: 20,
  gridWidth: 20,
  gridHeight: 20,
});

game3.place(patterns.pulsar, 1, 1);
game.start();
import { conway, patterns } from "@rankdim/conway";

const game = conway("conway-1", {
  cellSize: 20,
  gridWidth: 20,
  gridHeight: 20,
});

game3.place(patterns.gosperGliderGun, 1, 1);
game.start();
import { conway, patterns } from "@rankdim/conway";

const game = conway("conway-1", {
  cellSize: 20,
  gridWidth: 20,
  gridHeight: 20,
});

game4.randomize(0.3)
game.start();

Minimal Example using CDN

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@rankdim/conway via CDN</title>
    <script src="https://unpkg.com/@rankdim/[email protected]/dist/conway.umd.cjs"></script>
  </head>
  <body>
    <canvas id="demo"></canvas>
    <script>
      game = conway.conway("demo");
      game.randomize(0.4);
      game.start();
    </script>
  </body>
</html>
Option Type Default Description
cellSize number 10 The size of each cell.
gridWidth number 50 The number of cells in the horizontal direction.
gridHeight number 50 The number of cells in the vertical direction.
backgroundColor string "rgba(255, 255, 255, 1)" The background color of the canvas.
cellColor string "rgba(13, 63, 68, 1)" The color of the living cells.
deadCellColor string "rgba(215, 74, 74, 0.5)" The color of the dead cells.
gridColor string "rgba(0, 0, 0, 0.1)" The color of the grid lines.
showGrid boolean true Whether to display the grid lines.
showDead boolean true Whether to display the dead cells.
animationSpeed number 600 The delay between each generation in milliseconds.
toroidal boolean true Whether the grid wraps around at the edges.

License

MIT

About

A lightweight library for beautiful game of life embeds.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published