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

pixelmanipulator

v5.5.7

Published

A super powerful Typescript library for cellular automation.

Downloads

98

Readme

PixelManipulator logo PixelManipulator View the Demo

js-standard-style View the Docs pixelmanipulator snyk score npm bundle size npm type definitions Coveralls CircleCI npm GitHub Repo stars License: GPL v3 or later

PixelManipulator is a TypeScript library that can run any two-dimensional cellular automata, such as "Conway's Game of Life," and "Rule 90." Inspired by the The Powder Toy.

About the demo View the Demo

The demo includes a full-view pixel array, with configurable size, along with a movable viewfinder - also with configurable size. Targeter lines - synced between the viewfinder and the full-view pixel array - are also equipped so you can line up your complicated large-scale builds. You can even disable the targeter lines, the "focus box;" a box indicating the location of the viewfinder, and the pixelCounter, a tool that lets you see how many of what pixel are present. Don't forget that the pixel placer menu lets you not only set a different element for alt, normal and control clicking, but lets you fill the full-view pixel array with a specified random percent of that element with only a button click. All this, and a newly added element customizer, allowing one to edit the color, name and loop attributes of an element.

Pre-programmed cellular automata include:

Getting Started with the library

NPM Package

In your project run one of these:

  • For yarn, yarn add pixelmanipulator
  • For npm, npm i pixelmanipulator

If you are using esmodules, you now can import it like this:

import { PixelManipulator, rules, Ctx2dRenderer } from 'pixelmanipulator'

A great starting point is this console-only demo.

To run the node demo

  1. Clone this repo.
  2. npm i
  3. npm run node-demo

For documentation, View the Docs

Old-school

Start with this html:

<!doctype html>
<html>
  <head>
    <script src="https://unpkg.com/pixelmanipulator@^5.5.7"></script>
  </head>
  <body>
    <canvas id="myCanvas"></canvas>
    <script>
      var canvas = document.getElementById("myCanvas")

      // Create a renderer that renders on that canvas
      var renderer = new pixelmanipulator.Ctx2dRenderer(canvas)

      // Create a PixelManipulator, setting the size to 400 by 400
      var p = new pixelmanipulator.PixelManipulator(renderer, 400, 400)

      // An example element to get you started.
      var gol = p.addElement( {
        name: "Conway's Game Of Life",

        // born on 3, survives on 2 or 3
        ...pixelmanipulator.rules.lifelike(p, 'B3/S23'),

        // the rgb color
        renderAs: [0, 255, 0]
      })

      // If your browser doesn't support spread syntax
      // (that's the `...`), then this works too!
      var rule_ninety = p.addElement({
        name: "Rule 90",
        renderAs: [147, 112, 219]
      })
      p.modifyElement(rule_ninety, pixelmanipulator.rules.wolfram(p, 'Rule 90'))

      // Randomly fill 15% of the canvas with "Conway's Game of Life"
      p.randomlyFill(gol, 15)

      // Watch it go!
      p.play()
    </script>
  </body>
</html>

Pixelmanipulator supports various browser-side module loaders, such as

  • CommonJS (CJS)
  • Asynchronus Module Definition (AMD)
  • And also supports a fallback to the namespaced global variable pixelmanipulator

For documentation, View the Docs

What is Conway's game of Life

Conway's game of life is a cellular automata with a few simple rules. All of these rules use a distance formula where it counts the both the pixels that are immidately touching the edges and the pixels that are immidately touching the corners. For example (givin that O is the cell, and X is one that is checked in the moore distance fourmula):

XXX
XOX
XXX

On an empty cell, if there are exactly three(3) living cells around it, then it is born. A cell will remain alive if there are exactly two(2) or three(3) living cells nearby. Elsewise, the cell either remains dead, or becomes dead.

Adding a basic life-type cellular automata

For life-type cellular automata (cellular automata that are like Conway's game of Life, but have different rules), there is a specific syntax for how to specify them: B3/S23. This syntax literally means "born on three(3), survive on two(2) or three(3)."

The example code above included B2/S23 (AKA "Conway's game of Life") as an example. Feel free to try out other patterns, like

  • Seeds B2/S
  • Highlife B36/S23
  • And more! (262144 combinations, 2^(9+9))