Overview
Introduction
The Cantor set is one of the oldest and most famous fractal-like constructions in mathematics, built from nothing more than a single rule applied over and over: remove the middle third of every segment you have left.
This tool renders that construction visually, enter a depth and watch the segment split, thin, and scatter across as many iterations as you choose, then download the result as SVG or PNG.
What Is Generate a Cantor Set?
A generator for the classic middle-thirds Cantor set, drawn as one horizontal row per iteration, stacked vertically from the untouched starting segment at the top to the chosen depth's result at the bottom.
There is no text input or output here, the entire interaction is a single numeric Depth control (0 to 8) that redraws the stacked rows live.
How Generate a Cantor Set Works
Row 0 starts as a single unbroken segment spanning the full width. At every subsequent row, each surviving segment from the row above is split into two: the first third of its length and the last third, with the middle third simply gone.
Because every segment splits into exactly two children each iteration, the number of segments doubles every row, row 1 has 2, row 2 has 4, row 5 has 32, and so on, while each individual segment shrinks to a third of its parent's length.
The rows are stacked with a fixed vertical gap so the whole history of the construction is visible in one image, then the whole drawing is rescaled to fit the SVG viewBox before export.
When To Use Generate a Cantor Set
Use it whenever you need a clean visual of the Cantor set for teaching real analysis, topology, or measure theory, its total length shrinks to zero while the point count stays uncountably infinite.
It's also a handy quick reference for anyone who wants to see, rather than just read about, how a few iterations of middle-third removal already produce a strikingly sparse pattern.
Often used alongside Generate an Asymmetric Cantor Set, Generate a Generalized Cantor Set and Generate a Smith-Volterra-Cantor Set.
Features
Advantages
- Renders the exact classic construction with no approximation, each row is the literal result of the middle-third removal rule.
- Stacking every iteration in one image makes the progressive thinning immediately visible without needing to regenerate row by row.
- Exports as clean vector SVG, so the result stays crisp at any size, or as a flattened PNG for quick sharing.
Limitations
- Depth is capped at 8 for renderability, the true Cantor set is defined as the limit after infinitely many iterations, which this tool can only approximate visually at a finite depth.
- The drawing shows 1D segments stacked as rows for visibility, it isn't a literal single-line rendering of just the final iteration.
Examples
Best Practices & Notes
Best Practices
- Start around depth 4 or 5 to see the characteristic self-similar gaps clearly before pushing toward the depth 8 maximum, where segments become very thin.
- Download as SVG if you plan to zoom in or edit the result afterward, since it stays sharp at any scale.
Developer Notes
The construction is implemented as `cantorRows`, a shared helper that stacks one row of line segments per iteration and applies a caller-supplied split function to every surviving interval; for the classic set that split function keeps `[start, length/3]` and `[start + 2*length/3, length/3]`, discarding the middle third exactly. Geometry is normalized into a 1000x1000 SVG viewBox with Y-flip handled by `normalizeGeometry` before rendering.
Generate a Cantor Set Use Cases
- Illustrating middle-third removal for a real analysis or topology lecture
- Generating a reference image of the Cantor set for a course handout or blog post
- Exploring how self-similar structure emerges from a single simple removal rule
Common Mistakes
- Expecting a single thin line at the final depth rather than the full stack of rows, the stacked view is intentional so every iteration stays visible at once.
- Assuming higher depth always looks meaningfully different, past depth 6 or so the visual change per extra iteration becomes subtle since segments are already very thin.
Tips
- Compare this tool's output against the Asymmetric Cantor Set Generator or Generalized Cantor Set Generator to see how changing the split ratio changes how quickly the pattern thins out.
- Try the Cantor Dust Fractal Generator to see the same middle-thirds idea extended into two dimensions.