Staaarter

Generate a Sierpinski Curve

Generates the Sierpinski curve (also called the Sierpinski square curve), a right-angle-turn space-filling curve built from an L-system, and renders it as SVG line art you can download. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
fractalgeneratorsvgl-system

Overview

Introduction

The Sierpinski curve is a right-angle-turn space-filling curve, a single continuous path that, as it winds back and forth with 45-degree turns, progressively fills a square-shaped region. This tool renders its standard L-system construction as SVG line art.

Enter an iteration count and the tool expands the curve's X production rule that many times, then draws the resulting one-stroke path so you can see the fill pattern grow denser with each step.

What Is Generate a Sierpinski Curve?

A documented space-filling curve, sometimes named the Sierpinski square curve to distinguish it from the triangular Sierpinski arrowhead curve. It shares the Sierpinski name and a family resemblance in how it's generated, but it fills a square-ish area rather than tracing a triangle's outline.

It's built from an L-system with axiom "F+XF+F+XF" and a single rule for the letter X, interpreted by turtle graphics with 45-degree turns, the same general technique used for the Sierpinski arrowhead curve, Peano curve, and other L-system fractals in this category, just with a different axiom, rule, and angle.

How Generate a Sierpinski Curve Works

The generator starts from the axiom "F+XF+F+XF" and repeatedly replaces every X in the string with "XF-F+F-XF+F+XF-F+F-X" for as many iterations as you enter, where F draws a segment forward, + turns 45 degrees one way, and - turns 45 degrees the other way.

X itself is a non-drawing placeholder letter used only to control where the rule expands; only the F letters in the fully expanded string move the turtle forward and draw a segment.

The expanded instruction string is walked by a turtle to produce line segments, which are then rescaled to fit the SVG viewbox and drawn as one continuous unbroken path.

When To Use Generate a Sierpinski Curve

Use it whenever you want a right-angle, square-filling curve for generative art, plotter-friendly line art, or teaching how L-system rules and turn angles change the shape a curve traces.

It's a useful comparison piece next to the Sierpinski Arrowhead Curve Generator, both carry the Sierpinski name and use turtle-graphics L-systems, but one fills a square region with right-angle turns and the other traces a triangle with 60-degree turns.

If you want the filled, recursively-subdivided triangle instead, use the Sierpinski Triangle Generator.

Features

Advantages

  • A documented space-filling curve with a fixed, unambiguous axiom and rule, not an invented variant.
  • Renders as one continuous unbroken path, well suited to pen-plotter or single-stroke line-art use cases.
  • Downloadable as both SVG (for further vector editing) and PNG (for quick use anywhere).

Limitations

  • It approximates a square-filling curve rather than a triangular gasket, despite sharing the Sierpinski name with the triangle and arrowhead curve, which can be confusing on first glance.
  • At higher iteration counts near the maximum of 6, the dense back-and-forth path can make individual segments hard to distinguish without zooming into the downloaded SVG.

Examples

Low iteration count

Input

Iterations: 1

Output

A simple angular zigzag of a handful of segments, hinting at the right-angle turning pattern.

At iteration 1 the axiom has only been expanded once, so the individual 45-degree turns are easy to follow.

Default iteration count

Input

Iterations: 4

Output

A dense, woven path that visibly fills a square-shaped region of the canvas.

The default of 4 shows the space-filling behavior clearly while staying quick to render and download.

Best Practices & Notes

Best Practices

  • Start at iteration 1 or 2 to see the individual right-angle turns clearly before increasing toward the maximum of 6, where the fill pattern dominates.
  • Download the SVG rather than the PNG if you plan to recolor, scale, or further edit the curve, vector output has no resolution limit.

Developer Notes

Implemented as the "sierpinski-curve" preset in the shared L-system engine: axiom "F+XF+F+XF", rule X: "XF-F+F-XF+F+XF-F+F-X", 45-degree turn angle, default 4 iterations, capped at a maximum of 6. Like every other L-system tool in this category, expansion and turtle interpretation go through the shared generateFractalFromPreset/L-system engine before geometry normalization and SVG rendering.

Generate a Sierpinski Curve Use Cases

  • Teaching how axiom, rule, and turn angle together determine an L-system curve's shape
  • Pen-plotter or single-stroke generative art referencing a square-filling motif
  • Downloadable SVG line art for design projects wanting a woven, right-angle fractal pattern

Common Mistakes

  • Expecting a triangular shape because of the Sierpinski name, this curve fills a square-ish region with right-angle turns, for the triangular version see the Sierpinski Triangle Generator or Sierpinski Arrowhead Curve Generator.
  • Setting iterations to the maximum right away, past 4 or 5 the path becomes dense enough to make individual segments hard to distinguish visually.

Tips

  • Compare it directly against the Sierpinski Arrowhead Curve Generator to see how axiom, rule, and turn angle alone produce a square-filling curve versus a triangular one.
  • Zoom into the downloaded SVG in a vector editor to trace the individual right-angle turns at higher iteration counts.

References

Frequently Asked Questions