At My Fingertips

Documentation

Sierpinski Triangle

A Sierpiński triangle is a fractal composition of equilateral triangles, where each triangle is subdivided into smaller equilateral triangles.

Sierpinski triangle

Equilateral Triangle

The Sierpiński triangle is a recursive construction. At the base case of the recursion, we want to draw an equilateral triangle.

equilateral triangle

If you already have an equilateral_triangle function in your toolbox, just from toolbox import equilateral_triangle instead.

Loading...

Sierpiński Triangle

Now let's implement the recursive sierpinski_triangle function. It takes two parameters: the side length of the Sierpiński triangle to be drawn (size), and the limit for the side length, at which the recursion stops and it simply draws a normal equilateral triangle.

recursive step

Each recursive function invocation composes three smaller Sierpiński triangles into a bigger Sierpiński triangle.

Loading...

Evolution of the Sierpiński Triangle

Let's visualize the evolution from a normal equilateral triangle to Sierpiński triangles with growing recursion depths (smaller and smaller limit values).

evolving triangles

Loading...

Explore Further

Different Shapes

The shape used at the base case does not necessarily have to be a triangle. You could use a square, or a circle, or any other shape. Try it out!

Loading...

Pascal's Triangle

The Sierpiński triangle is related to Pascal's triangle: try to color the cells of Pascal's triangle with 2n rows if they are odd, and leave the even cells white.

Pascal

Loading...

Cantor Dust

A fractal that is closely related to the Sierpiński triangle is Cantor dust. Check out the PyTamaro iconCantor dust activity to discover more!

What You Learned

You discovered a beautiful fractal, and you learned how fractals are recursive compositions. You learned to implement this composition by writing a recursive function (sierpinski_triangle, which calls itself).


This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.

Sierpinski Triangle

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy PolicyPlatform Version 0d7866a (Fri, 20 Dec 2024 07:46:38 GMT)