The Sierpinski Carpet is a plane fractal curve i.e. a curve that is homeomorphic to a subspace of plane. It was first described by Waclaw Sierpinski in 1916. In these type of fractals, a shape is divided into a smaller copy of itself, removing some of the new copies and leaving the remaining copies in specific order to form new shapes of fractals.
How is it constructed?
The Sierpinski Carpet starts with a square. This square is divided into nine equal parts. The centremost smaller square is removed from the original larger square. The remaining square pieces are then again divided into nine equal parts and the centermost square from each square is removed. On repeating this process, a beautiful pattern of Sierpinski Carpet is observed.
Suppose we start with a black square.
We divide it into 9 equal pieces and remove the center square.
On further repeating the process, it results in something like this.
We can visualize this phenomenon in details in this video.
Let us see what its code looks like :
This is the Sierpinski Carpet after 7 repetitions. You can get its code for other languages on rosettacode.
- Sierpinski triangle
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- Python | Merge Python key values to list
- Python | Add Logging to a Python Script
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- Any & All in Python
- pow() in Python
- SQL using Python | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.