Staaarter

Generate a Sierpinski Maze

Generates the same recursive 3x3-minus-center subdivision used by the Sierpinski carpet, but draws every surviving cell as a line-art outline rather than a filled square, so the connected boundaries read as maze corridors. Adjust the Depth input from 0 to 4 and export the result as SVG or PNG. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
fractalgeneratorsvg

Overview

Introduction

The Sierpinski carpet is usually drawn as a flat, solid pattern, squares within squares with the centers punched out. This tool takes that exact same recursive subdivision and draws it a different way, as outlines only, so the boundaries between surviving cells link up into something that looks like a maze of corridors.

It's a rendering variation on a well-known fractal rather than a new mathematical construction, the underlying subdivision rule is identical to the standard carpet.

What Is Generate a Sierpinski Maze?

A generator that applies the Sierpinski carpet's recursive 3x3-minus-center subdivision, then renders every surviving cell as a four-sided line outline instead of a filled square.

Where the carpet is normally shown as solid shapes against empty space, this tool inverts the visual emphasis onto the cell boundaries themselves, producing a lattice of nested square corridors.

How Generate a Sierpinski Maze Works

Starting from a single square, the tool splits it into a 3x3 grid of nine equal sub-cells and discards the center one, exactly as the classic carpet does. It then recurses into each of the 8 remaining sub-cells and repeats the same 3x3-minus-center split, down to the chosen Depth.

Once recursion bottoms out, every surviving cell at every level is drawn as an outline, its four edges as separate line segments, rather than filled in. Because cells at different depths sit directly next to and inside one another, their combined outlines form a dense, connected network of corridor-like boundaries.

Increasing Depth adds another round of subdivision to every surviving cell, tripling the density of nested outlines and shrinking the smallest corridors by a further factor of three.

When To Use Generate a Sierpinski Maze

Use it when you want a Sierpinski-style fractal pattern that reads visually as a maze or circuit-board layout, for backgrounds, generative art, or laser-cut/CNC line-art references.

If you want the traditional filled-square look of the carpet instead, this specific outline rendering isn't the right choice, look for a filled carpet generator instead.

Features

Advantages

  • Produces a visually distinct maze-like pattern from a well-understood, easy-to-reason-about recursive rule.
  • Outline-only rendering keeps the SVG output lightweight, it's line segments rather than filled polygons.
  • Fully deterministic, the same Depth always produces the identical layout, useful for reproducible design work.

Limitations

  • Not a functional maze, there's no guaranteed entrance, exit, or connectivity between every corridor.
  • Depth is capped at 4, since the cell outlines become too small and dense to render legibly beyond that.

Examples

Depth 3 maze

Input

Depth: 3

Output

A lattice of nested square outlines three levels deep, each larger cell missing its center, forming a dense grid of connected corridor-like boundaries.

Every one of the surviving cells from depth 2 is subdivided once more into a 3x3 grid with its center dropped, then outlined.

Best Practices & Notes

Best Practices

  • Start at a low Depth (1 or 2) to see the base subdivision clearly before increasing it, the pattern gets visually dense fast.
  • Export as SVG when you need to scale or further edit the corridor lines, and PNG when you just need a flat image.

Developer Notes

The geometry comes from the same `subdivideGrid` helper the carpet and square generators share, called with a 3x3 grid and a `keep(row, col)` predicate that drops the center cell (row 1, col 1). Rather than pushing the surviving cells as filled `Rect` shapes, `generateSierpinskiMaze` maps each resulting rect into four `LineSegment`s (top, right, bottom, left), so the SVG renders `<path>` strokes instead of `<rect>` fills. Depth is bounded to 0-4 by the shared `boundsCheck` helper.

Generate a Sierpinski Maze Use Cases

  • Generative art backgrounds with a fractal, circuit-board-like texture
  • Line-art references for laser cutting or CNC engraving
  • Teaching recursive subdivision by contrasting the filled carpet against this outline rendering

Common Mistakes

  • Expecting a solvable maze with a clear path from edge to edge, the outlines are just carpet-subdivision boundaries, not a designed puzzle.
  • Jumping straight to Depth 4, which produces a very dense pattern, without first checking Depth 1 or 2 to understand the base rule.

Tips

  • Compare this tool side by side with Sierpinski Square Generator to see how the same idea of dropping cells looks with a different subdivision rule.
  • Download the SVG if you plan to recolor or restyle the strokes later, it keeps the corridor lines as editable vector paths.

References

Frequently Asked Questions