At My Fingertips

Documentation

Cantor Dust

Cantor dust is a fractal composition of squares, where each square is recursively subdivided into a three-by-three grid containing four squares in its corners.

Cantor Dust

Square

Cantor dust is a recursive construction. At the base case of the recursion, we want to draw a square.

If you already have a square function in your toolbox, feel free to instead from toolbox import square.

Loading...

Matrix

Let's create a function that can compose a list of lists of graphics into a two-dimensional matrix. The outer list represents the rows, the inner lists represent the cells in each row.

Using that function, let's create the following graphic:

level 1

Loading...

Cantor Dust

Now let's implement the recursive cantor_dust function. It takes two parameters: the side length of the Cantor dust to be drawn, and the iterations to denote the depth of the recursion.

Here is the result of cantor_dust(256, 3):

dust 3

Each recursive function invocation composes four smaller Cantor dust graphics into a bigger Cantor dust graphic; the base case (iterations == 0) just draws a square.

Loading...

Evolution of Cantor Dust

Let's visualize the evolution from a normal square to Cantor dust with growing recursion depths (larger and larger iteration counts).

Loading...

Explore Further

Cantor dust is related to other fractals. Feel free to explore them. Here are some ideas:

Sierpiński Carpet

Instead of keeping the four corners of the three-by-three grid, you also could keep other grid cells. For example, you could generate a Sierpiński carpet (similar to the PyTamaro iconSierpiński triangle), by removing only the middle cell of the three-by-three grid.

Loading...

Cantor Set

The Cantor dust we produced here is a two-dimensional variant of the Cantor set. You could visualize a one-dimensional Cantor set, and you could visualize the evolution of the one-dimensional Cantor set by placing Cantor sets with gradually larger iteration counts above each other.

Loading...

What You Learned

In this activity you learned about a fractal named "Cantor dust". To compose that fractal, you used a recursive function (cantor_dust, which calls itself). To terminate the recursion you used an if-statement, and to compose the three-by-three matrix, you practiced nested for-loops.


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

Cantor Dust

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)