- Elixir 94%
- CSS 3%
- JavaScript 2%
- Docker 1%
- Shell <1%
- 1 more language <1%
Maze Generator #
A maze generator built with Elixir and Phoenix LiveView. Supports four grid types, each rendered as a downloadable SVG.
Grid types #
| Grid | Description |
|---|---|
| Rectangular | Standard grid with optional over/under weave crossings and drop shadows |
| Hexagonal | Pointy-top hexagons with odd-r offset layout |
| Triangular | Alternating upright △ and inverted ▽ triangles |
| Spectre | Aperiodic tiling based on the Smith–Myers–Kaplan–Goodman-Strauss monotile (2023) |
All four use the Recursive Backtracker (depth-first search) algorithm, which produces long, winding corridors with relatively few dead ends.
Architecture #
lib/
maze/
maze/
cell.ex – Rectangular cell struct
grid.ex – Rectangular grid (links, crossings)
hex_cell.ex – Hex cell struct (6 directions)
hex_grid.ex – Hexagonal grid
tri_cell.ex – Triangle cell struct (upright/inverted)
tri_grid.ex – Triangular grid
spectre_grid.ex – Aperiodic spectre monotile grid
algorithms/
recursive_backtracker.ex – DFS maze algorithm (works with any grid)
maze_web/
live/
maze_live.ex – LiveView: controls + SVG rendering
components/
maze_svg.ex – Rectangular SVG (inset walls, weave, shadows)
hex_maze_svg.ex – Hexagonal SVG
tri_maze_svg.ex – Triangular SVG
spectre_maze_svg.ex – Spectre SVG
Rectangular grid and weaving #
Cells are addressed by {row, col} tuples. The grid tracks open passages
in a MapSet of canonical {min, max} pairs. When weaving is enabled, the
algorithm can carve a passage that crosses over or under an existing passage;
crossings are recorded separately and rendered with inset walls and an
optional drop shadow.
Hexagonal grid #
Uses a pointy-top orientation with odd-r offset coordinates. Each cell has
six neighbours: :northwest, :northeast, :east, :southeast,
:southwest, :west. The offset formula differs for even and odd rows.
Triangular grid #
Each cell is either upright (△, rem(row + col, 2) == 0) or inverted (▽).
Upright cells connect north, east, and south; inverted cells connect south,
west, and north. The SVG renderer draws each triangle from its three vertices.
Spectre grid #
The spectre monotile is a 14-sided polygon whose tiling is generated by a substitution system with nine metatile types (Gamma, Delta, Theta, Lambda, Xi, Pi, Sigma, Phi, Psi). Each metatile expands into eight children according to fixed rules; at the leaf level every metatile resolves to one spectre polygon (Gamma resolves to two).
Adjacency is detected by finding edges shared by exactly two tiles (matched by rounded vertex coordinates). Cell IDs are integers assigned in tiling-generation order.
The substitution algorithm is ported from the Python reference implementation by shrx, which is itself based on the original paper and Kaplan's reference code.
| Depth | Approx. tiles | Generation time |
|---|---|---|
| 2 | ~50 | < 100 ms |
| 3 | ~350 | < 500 ms |
| 4 | ~2 500 | ~2–5 s |
Recursive Backtracker #
The algorithm is grid-agnostic: it dispatches through the struct's own module
(%{__struct__: grid_mod}), so any grid that implements unvisited_neighbours/2,
weave_candidates/2, and link/3 works automatically. Weaving is opt-in
per grid type — hex, triangular, and spectre grids always return [] from
weave_candidates/2.
Running locally #
mix setup # install deps + build assets
mix phx.server # visit http://localhost:4000
Run tests:
mix test
mix precommit # compile (warnings-as-errors) + format + test
Deployment #
Docker Compose #
cp .env.example .env
# Edit .env — set PHX_HOST and generate SECRET_KEY_BASE:
# mix phx.gen.secret
docker compose up -d
The app listens on port 4000. Put a reverse proxy (nginx, Caddy, etc.) in
front of it for TLS termination; the app reads the x-forwarded-proto header
and redirects HTTP → HTTPS automatically.
Docker Hub #
A pre-built image is published automatically by GitHub Actions on every push
to main and on v* version tags. To use it directly:
docker pull suranyami/maze:latest
docker run -d \
-e SECRET_KEY_BASE=<64-byte secret> \
-e PHX_HOST=maze.example.com \
-p 4000:4000 \
suranyami/maze:latest
GitHub Actions setup #
Add two secrets to your repository (Settings → Secrets and variables → Actions):
DOCKERHUB_USERNAME— your Docker Hub usernameDOCKERHUB_TOKEN— a Docker Hub access token (hub.docker.com → Account Settings → Security → Access Tokens)
The workflow in .github/workflows/docker-publish.yml builds the image and
pushes it tagged as latest (on main) and as 1.2.3 / 1.2 / 1 (on
v* tags), plus a sha-<short> tag on every push.