https://github.com/jamis/scruffy-labrador
A flexible JavaScript implementation of a grid/graph, and some maze generation algorithms
https://github.com/jamis/scruffy-labrador
Last synced: 7 months ago
JSON representation
A flexible JavaScript implementation of a grid/graph, and some maze generation algorithms
- Host: GitHub
- URL: https://github.com/jamis/scruffy-labrador
- Owner: jamis
- Created: 2015-08-26T03:17:41.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-12-27T14:50:00.000Z (over 10 years ago)
- Last Synced: 2025-03-30T03:01:31.586Z (about 1 year ago)
- Language: JavaScript
- Size: 50.8 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Scruffy Labrador

A graph implementation in Javascript, with a focus on representing,
creating, and visualizing mazes. It has an emphasis on flexibility, and
eventually a bit more emphasis on usability, but for now you kind of have
to jump through more hoops than you might expect.
Like its namesake, it doesn't look like much, but it's there when you
need it! (I mean, look at him... Aw... Cute little guy...)
## Usage
First, concatenate the source files using `rake`:
$ rake build
This will generate a file called `scruffy-labrador.js`. Include this
on your webpage:
Initialize a grid by requiring the appropriate modules:
var Grid = require('grid').Grid;
var Layout = require('layout/orthogonal').Layout;
// a grid of 10 rows and 20 columns
var grid = new Grid(new Layout(10, 20));
Generate a maze:
var Backtracker = require('algorithm/recursive_backtracker').Algorithm;
new Backtracker().run(grid);
Generate geometry for the maze:
var Outlines = require('geometry/orthogonal/outlines').Outlines;
// build the geometry so that each cell is 20 units (pixels)
// on a side.
var geometry = new Outlines(grid, 20);
Draw the given geometry onto an HTML canvas element (assuming it has
an id of "maze"):
var canvas = document.getElementById('maze');
var ctx = canvas.getContext('2d');
// Mazes of up to 4-dimensions can be created. As this is
// just a two dimensional maze, we only want the layers from
// "world" 0, "level" 0.
//
// Layers are just arrays of elements, which should be drawn
// in the given order so that z-ordering is respected.
var layers = geometry.layers[0][0];
for(var i = 0; i < layers.length; i++) {
var layer = layers[i];
for(var j = 0; j < layer.length; j++) {
var element = layer[j];
element.render(ctx);
}
}
While they aren't implemented yet, the architecture is such that grids
of various (non-orthogonal) geometries can be represented, too, such
as hexagons, triangles, and so forth.
And speaking of architecture...
## Architecture
The code makes a few (possibly unusual, possibly insane) architectural
choices, in the name of experimentation and exploration. A simple
module loader is included (see `module.js`), which allows modules to
register themselves, and subsequently be loaded by other modules. As
this duplicates functionality already present in a variety of other
projects, it will probably be replaced eventually.
## Author
Jamis Buck
## License
To the extent possible under law,
Jamis Buck
has waived all copyright and related or neighboring rights to
Scruffy Labrador.
This work is published from:
United States.