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

squarestarjs

v0.4.3

Published

Asynchronous A* Pathfinding API

Downloads

6

Readme

HTML5/Javascript Pathfinding Library

Click here for a demonstration

Installation

  • Web: Find the minified file in the /bin directory
  • node.js: npm install easystarjs
  • Phaser: see Phaser Plugin
  • Bower: bower install easystarjs

Description

easystar.js is an asynchronous A* pathfinding API written in Javascript for use in your HTML5 games and interactive projects. The goal of this project is to make it easy and fast to implement performance conscious pathfinding.

This fork uses simple one-dimensional arrays as grid in contrast to the original easystar.js.

Features

  • Calculates asynchronously for better overall performance
  • Simple API
  • Small. ~7kb
  • Use it with any existing Javascript Framework
  • TypeScript support

API

Main Methods

var easystar = new EasyStar.js();
easystar.setGrid(oneDimensionalArray);
easystar.setAcceptableTiles(arrayOfAcceptableTiles);
easystar.findPath(startX, startY, endX, endY, callback);
easystar.calculate();

Additional Features

easystar.setIterationsPerCalculation(someValue);
easystar.avoidAdditionalPoint(x, y);
easystar.enableDiagonals();
easystar.enableCornerCutting();
easystar.setAdditionalPointCost(x, y, cost);
easystar.setTileCost(tileType, multiplicativeCost);
easystar.enableSync();
easystar.setDirectionalCondition(x, y, [EasyStar.TOP, EasyStar.LEFT]); // only accessible from the top and left
var instanceId = easystar.findPath(startX, startY, endX, endY, callback);
// ...
easystar.cancelPath(instanceId);

Usage

First create EasyStar.

// for web
var easystar = new EasyStar.js();

// for node.js
var easystarjs = require('easystarjs');
var easystar = new easystarjs.js();

Create a grid, or tilemap. You may have made this with a level editor, or procedurally. Let's keep it simple for this example.

var grid = [0,0,1,0,0,
            0,0,1,0,0,
            0,0,1,0,0,
            0,0,1,0,0,
            0,0,0,0,0];

Set our grid.

easystar.setGrid(grid);

Set tiles which are "walkable".

easystar.setAcceptableTiles([0]);

Find a path.

easystar.findPath(0, 0, 4, 0, function( path ) {
	if (path === null) {
		alert("Path was not found.");
	} else {
		alert("Path was found. The first Point is " + path[0].x + " " + path[0].y);
	}
});

EasyStar will not yet start calculating my path.

In order for EasyStar to actually start calculating, I must call the calculate() method.

You should call easystar.calculate() on a ticker, or setInterval.

If you have a large grid, then it is possible that these calculations could slow down the browser. For this reason, it might be a good idea to give EasyStar a smaller iterationsPerCalculation value via

easystar.setIterationsPerCalculation(1000);

It may take longer for you to find a path this way, but you won't completely halt your game trying to find one. The only thing left to do now is to calculate the path.

easystar.calculate();

License

easystar.js is licensed under the MIT license. You may use it for commercial use.

Running the demo locally

In order to run the demo you will need node.js, and npm installed.

git clone https://github.com/prettymuchbryce/easystarjs.git

cd easystarjs/demo

npm install

node app.js

Open your browser to 127.0.0.1:3000 to see the example.

Testing

npm run test

Support

If you have any questions, comments, or suggestions please open an issue.