EditSafely

Generate a Sierpinski Carpet

Draw a Sierpinski carpet fractal. Runs entirely in your browser, so your data never leaves your device.

Output

The result appears here as you type.

Options

How to use Generate a Sierpinski Carpet

  1. 1. Set the recursion depth. Choose Depth for how many times the center square of each remaining square gets removed. A depth-4 carpet already contains 4,096 filled squares.
  2. 2. Size the canvas. Set Width (px) and Height (px) to fit the carpet's grid of holes, keeping the canvas square so the 3x3 subdivision pattern stays proportional at every level.
  3. 3. Pick colors and line width. Choose Line color, Background color and Line width to make individual filled squares distinguishable, especially at higher depths where squares get very small.
  4. 4. Review the rendered carpet. The tool draws the Sierpinski carpet as an SVG of filled squares, with a hole removed from the center of every 3x3 subdivision at each level. Save it once the depth looks right.

When to use Generate a Sierpinski Carpet

Generate a Sierpinski Carpet draws the two-dimensional analog of the Cantor set, repeatedly removing the center square from a 3x3 grid of squares. It is the square counterpart to the more famous triangular Sierpinski gasket and a standard example of a fractal with zero area but infinite perimeter.

  • Teaching two-dimensional fractal removal. After the Cantor set removes middle thirds from a line and the Sierpinski triangle removes middle triangles, the carpet extends the same idea to removing center squares from a grid.
  • Illustrating fractal dimension between 1 and 2. The Sierpinski carpet has a fractal dimension around 1.89, a useful example for showing that fractal dimension can fall strictly between the familiar integer dimensions of a line and a plane.
  • Designing a filter or mesh pattern. The carpet's regular grid of holes at multiple scales makes a good basis for a decorative screen, laser-cut panel design, or textured background at a chosen depth.
  • Comparing to the Sierpinski maze variant. Render the filled carpet next to the outline-only Sierpinski maze at the same depth to show how the same hole pattern looks as solid squares versus corridor walls.

Examples

A depth-4 Sierpinski carpet

Output

An SVG drawing of the Sierpinski carpet made of 4096 filled squares.

About the Generate a Sierpinski Carpet tool

Generate a Sierpinski Carpet does its work locally, right in the browser. Draw a Sierpinski carpet fractal. There is no upload step, no queue and no account, and your data never travels over the network.

It belongs to the Math Tools collection on EditSafely, a set of 234 small, focused Math utilities that share the same instant, private workspace.

You can shape the output with 6 settings, including Depth, Width (px), Height (px) and Line color, and the result refreshes the moment you change one. A worked example further down the page shows exactly what the tool produces for a real input.

Running locally also makes the tool fast and dependable: results appear as you type or drop a file, there is no server outage that can take it down mid-task, and confidential data can be processed without a second thought.

Frequently asked questions

Does Generate a Sierpinski Carpet cost anything?

Yes, it is completely free. All 2,658 tools on EditSafely work without an account, a subscription or usage limits.

Does the generator send anything to a server?

No data leaves your device. The whole tool is JavaScript that runs inside your browser tab, so there is no upload, no server-side processing and no log of what you did. If you disconnect from the internet after the page loads, it keeps working.

How do I get a different result?

Run the generator again. Each run is computed fresh on your device, and any options you change are applied to the next result immediately.

Do I need to sign up or install anything?

Nothing to install and no account needed. Open the page in any up-to-date browser, including on a phone or tablet, and the tool is ready.

Can I save what the tool produces?

Yes. Use the download or copy controls in the output panel to keep the rendered result once it looks the way you want.

Related tools

All Math Tools