Advanced maze generator supporting many different maze types and generation algorithms, configurable in JSON. Mazes can be solved with the A* algorithm, braided, distance mapped, and exported to PNG, JPG, BMP, GIF or SVG.
Just drag-and-drop the configuration file on the .bat file or do one of these by command line:
mazegen config-file [additional-config-files...]
java -jar mazegen.jar config-file [additional-config-files...]
See releases.
Distance maps are color maps where each color represent the minimum distance from the cell from a starting cell. Distance maps can be used to reveal the "texture" of mazes created by each algorithm (see table above). All maze types support distance maps.
The algorithm uses Dijkstra's and the current implementation runs in O(n²) so it might get very slow for mazes with over 100 000 cells.
You can use the tool at http://gka.github.io/palettes for nice color gradients.
The generator is configured with a JSON file. There are many attributes but most of them are optional. In fact, here's the minimal configuration file:
{"mazes": [{"size": 10}]}
This will generate a single 10x10 orthogonal maze, export it to the current path with default styling settings.
Here's another more complete example:
{
"mazes": [
{
"name": "labyrinth",
"count": 1,
"type": "orthogonal",
"size": 10,
"algorithm": "aldous-broder",
"braid": "50%",
"openings": [["S", "S"], ["E", "E"]],
"solve": true,
"distanceMap": true,
"distanceMapStart": ["S", "S"],
"separateExport": false
}
],
"output": {
"format": "svg",
"path": "mazes/",
"svgOptimization": 3,
"svgPrecision": 2
},
"style": {
"cellSize": 30,
"backgroundColor": "#00FFFFFF",
"color": "#000000",
"strokeWidth": 3,
"solutionColor": "#0000FF",
"solutionStrokeWidth": 3,
"strokeCap": "round",
"distanceMapRange": "auto",
"distanceMapColors": ["#ffffff", "#000000"],
"antialiasing": true
}
}
This will generate a 10x10 orthogonal maze with Aldous-Broder's algorithm, export it to mazes/labyrinth.svg
in the most optimized SVG format.
Maze will be solved for the top-left to the bottom-right corners. Half deadends will be removed (braid).
A distance map will be generated starting from the top-left cell.
Custom styling settings are used, but in this case they all match default ones.
More examples of configuration file are available at /mazes/config/
.
maze
(required): array of maze set objects. A maze set is a group of mazes with the same properties, each with the following attributesname
: name of the set and of the file to be exported. Default ismaze
.count
: number of mazes to generate for this set. Default is1
.type
: maze type, one oforthogonal
,weaveOrthogonal
,unicursalOrthogonal
,delta
,sigma
,theta
,upsilon
,zeta
. Default isorthogonal
.size
(required): maze size, either an integer or an object. The object can have the following attributes:size
: maze size. If maze takes 2 dimensions, both will be the same. For theta mazes, useradius
instead.width
: maze width.width
: maze height.radius
: maze radius for theta maze.centerRadius
: center radius for theta maze. The number is the ratio between the center radius and the size of a cell. Default is1
.subdivision
: subdivision setting for theta maze. For example, if value is1.5
, a cell will be split in two when its size is 1.5 times the base size. Default is1.5
maxWeave
: maximum weave setting for weave orthogonal maze. The number is the maximum number of cells a passage can go over or under. If value is0
, the maze won't weave. Default is1
.
shape
: maze shape for delta and sigma mazes. One ofrectangle
,triangle
,hexagon
,rhombus
(parallelogram). Default isrectangle
.algorithm
: algorithm to use for maze generation, either a string or an object. If a string, any value fromab
,bt
,el
,gt
,hk
,kr
,pr
,rb
,rd
,sw
,wi
,aldous-broder
,binary-tree
,eller
,growing-tree
,hunt-kill
,kruskal
,prim
,recursive-backtracker
,recursive-division
,sidewinder
,wilson
. Default isrb
. If an object, it can take the following attributes:name
(required): algorithm name, see the values above.weights
: weights for the Growing Tree algorithm, an array of 3 integers. Values of the array are weights for choosing the random, the newest or the oldest in order. Default is[1, 1, 0]
bias
:- Side bias for the Binary Tree algorithm, one of
ne
,nw
,se
,sw
(n being north, e is east, etc). Default isne
. - Direction bias for Eller's algorithm, array of two percent values from
0%
(exclusive) to100%
. First value in the percentage of the time a wall is carved east, second value is the percentage of the time a wall is carved south. Default is["50%", "50%"]
.
- Side bias for the Binary Tree algorithm, one of
braid
: braiding setting, either an integer or a percent string, for example50%
. Braiding removes a certain number of deadends from the maze by connecting them with neighbouring cells. Default is0
.openings
: array of openings to carve in the maze. An opening is described by a position, which is another array. For example["S", "S"]
describes a position at the horizontal and vertical start of the maze. Valid letters areS
for start,C
for center andE
for end. Absolute position can also be described with coordinates, for example[0, 0]
, which is the top-left corner in an orthogonal maze but also is the center cell in a theta maze. Openings position must be unique and valid.solve
: whether to solve the maze or not, a boolean. Default isfalse
. Solving requires at least two openings, and if more are present, only the solution for the two first openings is displayed.distanceMap
: whether to generate a distance map or not, a boolean. Default isfalse
.distanceMapStart
: the starting cell for the distance map (for Dijkstra's). Can either be in the same format as an opening inopenings
, orrandom
for a random position. Default israndom
.separateExport
: If true, the maze, the solved maze and the distance mapped maze are exported as separate files instead of combined.
output
: Output settings, with the following attributes:format
: output format, one ofpng
,jpg
,bmp
,gif
,svg
. Default ispng
.path
: output destination path. Default is the current folder.svgOptimization
: the optimization level of SVG output from 0 to 4. Default is1
. A higher level results in more optimized file size but takes longer to export. This feature is experimental and values above1
may not work for some maze types like theta and weave orthogonal.svgPrecision
: the precision used for all numbers in SVG output. Default is2
.
style
: Styling settings, with the following attributes:cellSize
: the size of a cell, in pixels. Default is30
.backgroundColor
: background color, a hex color string. Default is#00FFFFFF
so that for PNG and SVG formats, it's transparent, but for other formats where the alpha channel is ignored, it's white.color
: the color to draw the maze with, a hex color string. Default is black,#000000
.strokeWidth
: the stroke width to draw the maze with. Default is3
.solutionColor
: the color to draw the solution with, a hex color string. Default is blue,#0000FF
.solutionSrokeWidth
: the stroke width to draw the solution with. Default is3
.strokeCap
: the stroke cap, one ofbutt
,round
orsquare
. Default isround
.distanceMapRange
: the distance range over which the distance map colors are distributed in a gradient. Default isauto
for automatic range matching the maze longest path.distanceMapColors
: the array of the distance map gradient colors. Default is["#ffffff", "#000000"]
.antialiasing
: whether to use antialiasing or not. Default istrue
.
A JSON schema file is available from config-schema.json
for autocomplete and basic validation.
The maze generator itself validates that parameters have a valid value by printing ERROR: ...
.
However, JSON exceptions for wrong types and missing attributes are not caught.
View changelog at CHANGELOG.md
.
- Jamis Buck for the explanation of all maze generation algorithms and for his book.
- Walter D. Pullen for information on maze types.
Everything is licensed under the MIT License.