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

gridworld

v0.1.3

Published

2D gridworld representation and canvas renderer, intended for experimentation with various game algorithms.

Readme

gridworld

This is a small module that provides a representation and canvas renderer for 2D "gridworlds". Its intended use is for experimentation with game and AI algorithms such as pathfinding, line-of-sight, plus any number of grid-based board games.

Here's what it looks like:

Gridworld

Installation

Browserify is recommended.

$ npm install gridworld

API

Creating a world

new GridWorld(canvasEl, width, height, [options])

Create a new GridWorld with a given width and height (specified in terms of grid cells) that will draw onto canvas.

Supported options:

  • cellSize size of each cell in pixels. Default: 32.
  • cellPadding size between each cell in pixels. Default: 1.
  • drawBorder if set, a border will be drawn around the entire world, instead of just between each cell.
  • borderColor default: 'black'.
  • backgroundColor default cell background color. Default: 'white'.
  • resizeCanvas if set, canvas element will be resized to fit world's dimensions, including any specified padding.
  • padding how much space to leave around the rendered world. Can be specified as a single number or as an object with keys top, right, bottom and left. Mostly useful with resizeCanvas option. Default: 0.
  • onclick click handler for cells. See event handling, below.

Example:

var GridWorld = require('gridworld').GridWorld;
var world = new GridWorld(canvas, map[0].length, map.length, {
  padding       : {top: 10, left: 10, right: 10, bottom: 60},
  cellSize      : 32,
  cellSpacing   : 1,
  resizeCanvas  : true,
  drawBorder    : true,
  onclick: function(node) {
    console.log("you clicked on node: " + node);
  }
});

Drawing the world

world.draw()

Draws the world on its canvas.

Setting world attributes

world.setBackgroundColor(x, y, color)

Set the background color of the node at (x,y) to color.

world.setBlocked(x, y, blocked)

Flag the cell at (x, y) as passable/impassable. A cell's passability does not affect how it is drawn.

world.setAttribute(x, y, attr, value)

Set arbitrary attribute attr on node (x,y) to value.

Iterating

world.eachNeighbour(x, y, callback)

Iterate over each Manhattan neighbour of node (x,y). Callback receives (x,y) co-ordinate of neighbour as a parameter.

world.eachNeighbourNode(node, callback)

Iterate over each Manhattan neighbour of node. Callback receives neighbour node object as a parameter.

world.eachNode(callback)

Iterate over each of the world's node objects. Callback receives node object as a parameter.

Event Handling

world.onclick = function(node) { /* ... */ }

Function to invoke when user clicks on a node. Receives clicked node as a paremeter.

TODO

  • Add event handlers for dragging
  • Allow markers to be overlaid on cells
  • Support optional diagonal neighbours