Generate Sierpinski Carpet
The Sierpinski Carpet Generator lets you create one of mathematics' most iconic fractal patterns directly in your browser, with full control over iteration depth, canvas dimensions, and colors. Named after Polish mathematician Wacław Sierpiński, who described it in 1916, this fractal is built by repeatedly subdividing a square into a 3×3 grid and removing the center cell, then applying that same rule to each of the eight remaining sub-squares — and again, and again, infinitely deep in theory. Our tool renders this recursive process visually, letting you explore how structure emerges from a simple rule applied at multiple scales. Whether you're a student learning about recursion and self-similarity, a teacher preparing a visual demonstration for a mathematics or computer science class, a graphic designer hunting for unique geometric textures, or a developer studying fractal algorithms, this tool gives you instant, high-quality output without writing a single line of code. You can dial up the iteration depth to watch the pattern grow denser and more intricate, adjust the canvas size to suit your resolution needs, and choose any fill and background colors to match your project's aesthetic. The rendered carpet can be copied or saved for use in presentations, artwork, educational materials, or generative design projects. Because the Sierpinski Carpet has a Hausdorff dimension of approximately 1.893 — sitting between a one-dimensional line and a two-dimensional plane — it serves as a visually compelling gateway into the study of fractional dimensions and mathematical infinity.
Carpet Size and Iterations
Carpet Colors
Curve
Output (Sierpinski Carpet)
What It Does
The Sierpinski Carpet Generator lets you create one of mathematics' most iconic fractal patterns directly in your browser, with full control over iteration depth, canvas dimensions, and colors. Named after Polish mathematician Wacław Sierpiński, who described it in 1916, this fractal is built by repeatedly subdividing a square into a 3×3 grid and removing the center cell, then applying that same rule to each of the eight remaining sub-squares — and again, and again, infinitely deep in theory. Our tool renders this recursive process visually, letting you explore how structure emerges from a simple rule applied at multiple scales. Whether you're a student learning about recursion and self-similarity, a teacher preparing a visual demonstration for a mathematics or computer science class, a graphic designer hunting for unique geometric textures, or a developer studying fractal algorithms, this tool gives you instant, high-quality output without writing a single line of code. You can dial up the iteration depth to watch the pattern grow denser and more intricate, adjust the canvas size to suit your resolution needs, and choose any fill and background colors to match your project's aesthetic. The rendered carpet can be copied or saved for use in presentations, artwork, educational materials, or generative design projects. Because the Sierpinski Carpet has a Hausdorff dimension of approximately 1.893 — sitting between a one-dimensional line and a two-dimensional plane — it serves as a visually compelling gateway into the study of fractional dimensions and mathematical infinity.
How It Works
Generate Sierpinski Carpet produces new output from rules, parameters, or patterns instead of editing an existing document. That makes input settings more important than input text, because the settings are what define the shape of the result.
Generators are only as useful as the settings behind them. When the output seems off, check the count, range, delimiter, seed values, or pattern options before judging the result itself.
All processing happens in your browser, so your input stays on your device during the transformation.
Common Use Cases
- Create a visual aid for a computer science lecture demonstrating how recursive algorithms build complex structures from simple rules.
- Generate a high-resolution Sierpinski Carpet image to use as a geometric background or texture in graphic design projects.
- Explore how increasing the iteration depth progressively removes area from the original square, illustrating convergence toward zero area.
- Use the tool in a high school or university mathematics class to introduce the concept of self-similarity and fractal geometry.
- Produce tiling-ready carpet-style patterns for digital art, textile design mockups, or decorative print layouts.
- Experiment with color combinations to understand how fractal patterns interact with contrast and negative space in visual composition.
- Benchmark or prototype a recursive rendering algorithm by comparing the tool's output to your own implementation.
How to Use
- Select your desired iteration depth using the depth control — start with 2 or 3 to see the basic pattern clearly, then increase toward 5 or 6 for a highly detailed fractal.
- Set the canvas width and height to match your intended use, whether that's a small preview thumbnail or a large high-resolution export suitable for print.
- Choose a fill color for the solid squares and a background color for the removed regions — high-contrast combinations like black and white or navy and gold work especially well.
- Click the generate or render button to draw the Sierpinski Carpet on the canvas using the settings you've configured.
- Inspect the rendered result and adjust any settings — try increasing depth by one step to see how the pattern becomes more intricate without changing its overall structure.
- Copy or download the finished image to use in your project, presentation, or artwork.
Features
- Adjustable recursion depth from 1 to 6+ levels, letting you control the balance between detail and rendering speed.
- Custom canvas width and height inputs so you can generate carpets at any resolution from small icons to large print-ready images.
- Full fill color picker for the solid square regions, supporting any hex or RGB color value.
- Full background color picker for the removed (empty) regions, enabling high-contrast or monochromatic designs.
- Instant in-browser rendering using HTML5 Canvas, with no server calls or software installation required.
- Clean, copyable output suitable for use in design tools, presentations, academic papers, or web projects.
- Mathematically accurate recursive subdivision that faithfully reproduces the Sierpiński Carpet pattern at every depth level.
Examples
Below is a representative input and output so you can see the transformation clearly.
Order: 0 Size: 100 Angle: 90
Path: (0,0) (100,0)
Edge Cases
- Very large inputs can still stress the browser, especially when the tool is working across many numbers. Split huge jobs into smaller batches if the page becomes sluggish.
- Empty or whitespace-only input is technically valid but may produce unchanged output, which can look like a failure at first glance.
- If the output looks wrong, compare the exact input and option values first, because Generate Sierpinski Carpet should be repeatable with the same settings.
Troubleshooting
- Unexpected output often means the input is being split or interpreted at the wrong unit. For Generate Sierpinski Carpet, that unit is usually numbers.
- If a previous run looked different, check for hidden whitespace, changed separators, or a setting that was toggled accidentally.
- If nothing changes, confirm that the input actually contains the pattern or structure this tool operates on.
- If the page feels slow, reduce the input size and test a smaller sample first.
Tips
Start at iteration depth 3 to get a feel for the pattern before pushing higher — depth 5 and above can produce very fine detail that only shows at larger canvas sizes, so pair high depths with larger dimensions for the best results. For print or high-visibility use, black on white or white on black gives the clearest demonstration of the fractal's structure. If you're using the carpet as a background texture in design work, try muted color combinations like light gray on dark gray so the pattern adds visual interest without competing with foreground content. When using this tool for teaching, generate the same carpet at depths 1, 2, 3, and 4 side-by-side to let students physically see how the self-similar rule builds complexity step by step.
Frequently Asked Questions
What is the Sierpiński Carpet?
The Sierpiński Carpet is a fractal pattern created by recursively subdividing a square into a 3×3 grid and removing the center sub-square, then repeating that process for each of the remaining eight sub-squares. It was first described by Polish mathematician Wacław Sierpiński in 1916. The pattern is self-similar, meaning any portion of it looks like a scaled-down copy of the whole. After infinite iterations, the total area of the carpet converges to zero despite the structure remaining geometrically complex.
What is the Hausdorff dimension of the Sierpiński Carpet?
The Sierpiński Carpet has a Hausdorff (fractal) dimension of log(8) / log(3), which is approximately 1.8928. This value falls between 1 (a line) and 2 (a filled plane), reflecting the fact that the carpet is more complex than a simple curve but never densely fills the 2D space it occupies. Fractal dimension is a way of measuring how an object scales and how much space it occupies compared to its topological dimension, and the Carpet's value near 1.893 places it among the denser two-dimensional fractals.
How does iteration depth affect the Sierpiński Carpet?
Each increase in iteration depth applies the removal rule one additional level deeper into the pattern. At depth 1 you see a 3×3 grid with one hole in the center; at depth 2 each of the eight remaining squares gets its own center removed; and so on. Higher depths produce finer detail and a denser-looking pattern of holes, but they also require more computational steps and benefit from larger canvas sizes to remain legible. Depths between 3 and 5 are generally the most visually rewarding for screen display, while depth 6 and above works best at high resolutions.
What is the difference between the Sierpiński Carpet and the Sierpiński Triangle?
Both are classic fractals introduced by Wacław Sierpiński, but they differ in geometry and construction. The Sierpiński Triangle is built from triangular subdivisions: each triangle is split into four smaller ones and the central triangle is removed, leaving three self-similar copies. The Carpet uses a square grid, removing the center of nine sub-squares to leave eight copies. The Triangle has a Hausdorff dimension of about 1.585, making it less area-dense than the Carpet's 1.893. Visually, the Triangle feels more open and angular, while the Carpet has a more regular, grid-like structure that lends itself to textile and tile-like patterns.
Can I use the generated Sierpiński Carpet image commercially?
The Sierpiński Carpet is a mathematical construction that has been in the public domain for over a century, so the pattern itself carries no copyright restrictions. Images you generate using this tool are your own output to use as you see fit, including in commercial projects, merchandise, and publications. As with any generative tool, check the platform's terms of service for any specific conditions, but in general the fractal geometry itself is free to use.
What real-world applications use the Sierpiński Carpet pattern?
Fractal antenna engineering is one of the most prominent real-world applications: carpet-inspired antenna geometries can receive signals across multiple frequency bands simultaneously in a compact footprint. Materials scientists have studied hierarchically perforated structures similar to the Carpet for acoustic insulation and fluid filtration, where the multi-scale hole arrangement produces useful scattering properties. In design and architecture, carpet-like fractal grids appear in decorative panels, laser-cut screens, and textile patterns. The pattern is also widely used in mathematics and computer science education to illustrate recursion, self-similarity, and fractal dimension.
What is the 3D version of the Sierpiński Carpet?
The three-dimensional analogue of the Sierpiński Carpet is called the Menger Sponge, introduced by Karl Menger in 1926. It is constructed by dividing a cube into a 3×3×3 grid of 27 smaller cubes, removing the center cube of each face and the very center cube (7 total), and repeating recursively. The Menger Sponge has a Hausdorff dimension of log(20) / log(3), approximately 2.727, and famously has infinite surface area while its volume approaches zero through successive iterations — a striking illustration of how fractal geometry defies everyday spatial intuition.
How do I choose the best canvas size for a detailed Sierpiński Carpet?
The ideal canvas size depends on your target iteration depth. Because the Carpet subdivides space by a factor of three at each level, a canvas width that is a power of 3 (such as 243, 729, or 2187 pixels) will map perfectly onto the fractal grid without any rounding artifacts. For depth 4, a 729×729 pixel canvas gives clean pixel-aligned rendering. For depth 5, 2187×2187 pixels ensures each smallest square is exactly one pixel. If you're generating for screen display at depth 3 or below, any reasonable square canvas will look sharp and clear.