# 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?

Simply put, it’s a list of (potentially non-linear) functions that iteratively manipulate some data. This is a very broad definition, however, and it may not seem obvious at first how we can use an IFS to our advantage to generate things such as fractals. In order to better explain how it’s used for this purpose, I’ll give an example below:

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.

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.

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:

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

A question that has always bugged me is *how* is this even possible. I understand the math, I understand what is going on “under the hood”, but it’s still mind-blowing to see order come from randomness and such simple rules. That’s what makes chaos theory/game so fascinating. Here’s a (broad) question to think about: are these fractals created or discovered? I mean, we invented the system used to represent and display these shapes, but these rules we’re just now discovering have existed long before we realized they were there. And with infinitesimally small variations producing such wildly different results, it would be impossible for anyone to discover every fractal that is hiding within the chaos. It serves as a reminder that our planet is also governed by sets of rules, some of which may be similar to the rules which govern fractals; judging by just how common fractal-like structures appear in nature. Others of which may extend deep into the cosmos, farther than we are able to discover as of now. There’s no telling what else is hiding from us.