Sierpiński triangle (#47)
Jonathan Frech
Having recently heard something about chaos theory, I was interested in the Sierpiński triangle. Specifically in the random generation. To prove that it can really be generated using a die, I wrote this program.
How it works
- You start with any point inside the triangle (I chose the center).
- A triangle has three points, let us call them 𝐴, 𝐵 and 𝐶.
- You choose randomly between one of those three points, go half the distance and set a pixel right there.
- Repeating this process over and over again (always starting at your last point), you eventually¹ get the Sierpiński triangle.
Controls
- “Space” toggles if the triangle is generated,
- “m” toggles if the current position is shown (indicated by a blue circle).



Source code: sierpinski-triangle.py
[1] | [2020-07-08] This post in particular was slightly edited to better reflect current standards. A note one may add is that “eventually” should really say “in the limit”, as no finite amount of time will lead to the true fractal using the described methodology. |
- pingback from #126