At My Fingertips

Rapid Playground

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 Sierpinski triangle is a recursive construction. At the base case of the recursion, we want to draw an equilateral triangle.

equilateral triangle

Let's implement a function to draw an equilateral triangle with a given size (side length) and color. Use PyTamaro's PyTamaro icontriangle function for this.

Loading...

Spierpinski Triangle

Now let's implement the recursive sierpinski_triangle function. It takes two parameters: the side length of the Sierpinski 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 Sierpinski triangles into a bigger Sierpinski triangle. To do this composition, use PyTamaro iconcompose and PyTamaro iconpin.

Loading...

Evolution of the Sierpinski Triangle

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

evolving triangles

Write a function evolving_triangles that places evolving Sierpinski trianges side-by-side.

Loading...

Explore Further

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!

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


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 f81ff6d (Thu, 02 May 2024 16:52:36 GMT)