Staaarter

Generate a Generalized Cantor Set

Builds our own generalization of the classic Cantor set's keep-ratio: instead of dividing each segment into 3 equal parts and keeping the outer 2, this variant divides into 5 equal parts and keeps 3 (the 1st, 3rd, and 5th fifths), producing three children per iteration instead of two, drawn as stacked rows and exported 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 classic Cantor set is really a special case of a more general idea: divide a segment into equal parts, keep some of them, and repeat. This tool explores a different point in that family.

Instead of the classic rule of dividing into 3 equal parts and keeping 2, this generator divides each segment into 5 equal parts and keeps 3 of them, the 1st, 3rd, and 5th fifths, producing three children per segment at every iteration instead of two.

What Is Generate a Generalized Cantor Set?

A generator for our own generalization of the classic Cantor set's keep-ratio rule, drawn the same way as the standard construction, one stacked row per iteration, but with each segment splitting into three children instead of two.

This is not a single fixed textbook object, it's a demonstration of how the classic middle-thirds idea extends to other divide-and-keep ratios.

How Generate a Generalized Cantor Set Works

Row 0 starts as a single unbroken segment. At every subsequent row, each surviving segment is conceptually divided into 5 equal fifths, and the 1st, 3rd, and 5th fifths are kept as new child segments while the 2nd and 4th fifths are discarded.

Because 3 children survive from every parent segment each iteration, the segment count triples every row, reaching 3^depth segments in the final row rather than the classic set's 2^depth.

Each surviving child is one-fifth the length of its parent, smaller relative to its parent than the classic set's one-third children, so the rows fill with more numerous, individually shorter segments as depth increases.

When To Use Generate a Generalized Cantor Set

Use it to illustrate that the Cantor set's core idea, self-similar removal at every scale, generalizes beyond the specific 3-parts-keep-2 rule to other divide-and-keep ratios and branch counts.

It's a useful visual contrast to the Asymmetric Cantor Set Generator: that tool changes the split's symmetry while keeping two children per segment, this one changes the branch count itself.

Features

Advantages

  • Demonstrates a genuinely different kind of variation from an uneven split, changing the number of surviving children per iteration rather than just their relative sizes.
  • Produces a visibly denser, more finely divided pattern at a given depth than the classic 2-child construction.
  • Exports as clean vector SVG or a flattened PNG, matching the other Cantor set tools in this category.

Limitations

  • This is our own generalization, not a single standard named object, so it won't appear under this exact name in a textbook.
  • Depth is capped at 6, lower than the classic set's 8, because the segment count grows faster (3^depth) and already produces a dense, hard-to-read row at higher depths.

Examples

Depth 0

Input

Depth = 0

Output

A single unbroken horizontal segment spanning the full width.

At depth 0, no division has happened yet.

Depth 3

Input

Depth = 3

Output

Four stacked rows, with the bottom row containing 27 segments (3^3), visibly denser than the classic Cantor Set Generator's 8 segments (2^3) at the same depth.

Each iteration produces 3 children per segment instead of 2, so segment count grows as 3^depth rather than 2^depth.

Best Practices & Notes

Best Practices

  • Compare it directly against the classic Cantor Set Generator at the same depth to see how the extra branch per segment changes the density of the result.
  • Keep depth at 4 or below for the clearest view of individual segments, since 3^depth segments become very numerous quickly.

Developer Notes

Implemented via the shared `cantorRows` row-stacking helper with a custom split function that returns `[start, length/5]`, `[start + 2*length/5, length/5]`, and `[start + 4*length/5, length/5]`, keeping the 1st, 3rd, and 5th fifths of each segment (60% of its length) split across three equal children instead of the classic set's two children from thirds.

Generate a Generalized Cantor Set Use Cases

  • Illustrating that the Cantor set's construction rule generalizes to other divide-and-keep ratios and branch counts
  • Producing a denser, more finely subdivided fractal-like pattern than the classic 2-child construction at a comparable depth
  • Side-by-side comparison against the classic and asymmetric Cantor set variants

Common Mistakes

  • Expecting this to keep more total length than the classic set, it actually keeps slightly less per iteration (60% versus about 66.7%), the density increase comes from more branches, not more surviving length.
  • Setting depth too high and losing the ability to distinguish individual segments, since 3^depth segments crowd the row quickly.

Tips

  • Try the Smith-Volterra-Cantor Set Generator next to see a construction aimed at keeping more total length rather than more branches.
  • Download as SVG to inspect the exact segment layout of a given depth at high zoom.

References

Frequently Asked Questions