A Brief Look at IFS Representation & Chaos Game

What’s quite fascinating about mathematics is when you can turn equations and numbers into art that looks pleasing to you and I. It helps build a narrative that simple rules somehow have the power to manifest images of infinite complexity. A great example of this would be the construction of self-similar fractals using something called an IFS (Iterated Function System).

What even is an IFS, anyway?

Say we have a 2D space, where each pixel is represented by an (x, y) coordinate location. Let’s define a point called “start” which contains the pair (0, 1). Now, let’s define two functions, both which perform two different operations when fed with a pair of coordinate points. We select a random integer between one and two, and depending on what number is selected, we input the starting coordinates into one of the two functions. The function will return a new coordinate pair, after the performed operations are complete. We then randomly select a new function which will use that new coordinate pair as an input. This process continues on for an arbitrary amount of iterations.

However simple this might sound, this is exactly how IFSs can be represented using a process known as the chaos game. I’ll use the Windows command prompt and a bit of C++ (including Window’s SetPixel function) to generate some fractals with the method above.

A Sierpiński triangle generated in console using an IFS and the chaos game.
Barnsley fern using the same method as above. (note: function selection is based on probability for the fern)

The most commonly generated fractals using this method is the Sierpiński triangle and the Barnsley fern, however this is only scratching the surface of what’s out there.

Lévy C curve, motion is generated by gradually reducing the denominator of each function until it reaches 2.

What’s more fascinating is that more often than not, these shapes are quite related to each other. Larry Riddle has shown one such case on his incredibly resourceful website, which details the relationship between the Lévy C curve (shown above) and another self-similar fractal called the Dragon curve. I’ve managed to implement this transformation using these two (slightly adjusted) functions from Larry’s website:

Animating this in the console by incrementing t by 0.05 per every 30,000 iterations gives this fascinating result:

Transformation from Dragon curve to Lévy C curve.

An interesting thing to note is that you can use any coordinate pair to start with, and the same fractal will be generated. This is precisely why these shapes are also referred to as strange attractors, especially when the conditions used to generate the fractal are random, or chaotic (like the method detailed in this post). By modifying the values inside each function, the resulting strange attractor changes in surprising ways.

The Epitome of Chaos

Writing about various STEM-related projects that I’m working on.