Text Maze
Create mazes with paths in the form of lines of text.
Use text-maze-render to render a text maze in a browser via the HTML Canvas API.
See it in use: https://littlesystem.com/maze
Description
Each maze is a 2D array. The value at each index in the nested arrays is a number indicating the type of location in the maze. The solution path follows negative values through the maze.
2
A path and part of the embedded text.1
A path but not part of the embedded text.0
Not a path.-1
As 1, but also on the solution path.-2
As 2, but also on the solution path.
Current character whitelist for text:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .?!'
Install
npm install --save text-maze
Options
width
Optional maze width. An array length. The maze is auto-sized for the browser when width is not given.margin
Optional margin in pixels. Used when auto-sizing, ignored when width is given. The following default margin values are used for auto-sizing when margin is not given: 30px for screens < 576px, 100px otherwise.
Usage
Import text-maze.
var tm = ;
Create an auto-sized maze.
var maze = tmmaze;
Get the auto-size values for use with the text-maze-render package.
var result = tm; var maze = resultmaze; // The maze.var endpoints = resultendpoints; // Know your endpoint coordinates.var cellSize = resultcellSize; // Render each maze location in a cellSize × cellSize square.
Create a maze of width
100. The cellSize property in the returned object will be null
.
var maze = tmmaze;
Create a maze auto-sized for the screen leaving 200 pixels of margin
.
var maze = tmmaze;
For use in a browser, bundle your code with something like browserify.
browserify code.js -o bundle.js