Introduction
One of my favorite movies growing up was the original Jurassic Park. I'll tolerate Lost World and Jurassic Park III, but we will not discuss those new ones. Sorry Chris Pratt, certified Raptor Bro. Anyway, later on, I learned there were books that the movies were based on so of course I had to read it. One of the key reasons why Dr. Malcolm was convinced the park would fail is Chaos Theory. The conversation goes as follows.
“[...] if I have a weather system that I start up with a certain temperature and a certain wind speed and a certain humidity—and if I then repeat it with almost the same temperature, wind, and humidity—the second system will not behave almost the same. It'll wander off and rapidly will become very different from the first. Thunderstorms instead of sunshine. That's nonlinear dynamics. They are sensitive to initial conditions: tiny differences become amplified.”
“I think I see,” Gennaro said.
“The shorthand is the 'butterfly effect.' A butterfly flaps its wings in Peking, and weather in New York is different.”
“So chaos is all just random and unpredictable?” Gennaro said. “Is that it?”
“No,” Malcolm said. “We actually find hidden regularities within the complex variety of a system's behavior. That's why chaos has now become a very broad theory that's used to study everything from the stock market, to rioting crowds, to brain waves during epilepsy. Any sort of complex system where there is confusion and unpredictability. We can find an underlying order. Okay?”
Chaos theory explores how seemingly random and unpredictable events arise from deterministic systems. A well-known example is the butterfly effect, introduced by Edward Lorenz, which suggests that a butterfly flapping its wings in Asia could ultimately influence the development of a storm in New York. A key concept in chaos theory is the sensitivity to initial conditions – small differences at the beginning of a process leading to vastly different outcomes.
This principle is demonstrated in the mathematical concept of the chaos game, where fractals emerge within a polygon through a recursive process applied to random points. There are other variations of the chaos game that plot points based on systems of equations combined with weighted probabilities. The fern at the beginning of this post is created using a chaos game simulator. But that's getting ahead of ourselves. I came across these fractals after looking into chaos theory after reading the Jurassic Park books, and I had no idea how these things actually work, because of this I want to build them in an attempt to break them down.
Sierpinsky's Triangle from a Chaos Games
Let's start with the simplest and most famous chaos game which creates Seirpinsky's Triangle. The game itself is pretty simple.
- Draw an equilateral triangle
- Pick a random point inside the triangle
- Pick a random vertex of the triangle
- Plot a point halfway between the initial point and the vertex
- Repeat steps 3 and 4 using the plotted point as your new initial point
Chaos games take many iterations to see the fractal. You can use the controls below to go through multiple steps, which will reveal the triangle we're after.
So why does this work? Sierpiński's triangle is self-similar, meaning that when you zoom in on a portion of the triangle, it looks similar to the rest. The rules and geometry of the triangle create unreachable regions, forming the pattern we see. For example, since the rule is to move halfway toward a randomly chosen vertex, the center of the triangle will never be visited because no sequence of moves can land there.
Looking at the triangle with the center omitted, you'll see that we've essentially created three smaller equilateral triangles and have picked a random point inside them.
Following the vertex selection and traversal rules, the middle of those triangles will eventually be omitted, creating more triangles.
This idea extends to other regions of the triangle, and over time, the randomness of point selection combines with the rules to refine the shape and reveal its intricate structure.
An interesting way to see the influence of the vertex selected on the overall shape is to color the vertex. Whenever that vertex is selected, color the dot with the matching color. Running the simulation again with this coloring applied, you can see that each vertex is responsible for plotting its own triangle.
Scaling Factor
The scaling factor or, r
, determines how far the next point moves towards the selected vertex each iteration. In the case of the game we
just played, r
was 0.5, as we took the midpoint between the initial poin and the selected vertex. The scaling factor is what ultimately
determines the fractals appearance. In the case of the equilateral triangle we have been looking at:
r
= 0.5 moves the points half way and creates Sierpiński's Triangler
< 0.5 spreads the points more and fills in the triangler
> 0.5 moves the points closer to the vertices
In order to keep the fractal inside the polygon, r
must be less than one; however there is nothing that says you cannot use an r
values
that is greater than one. A scaling factor greater than one, will move the points outside the triangle but still give someinteresting patterns.
In the simulator below, there is a field where you can now control r
, try a couple different values out for yourself!
Note: if you make
r
too big the points will be outside the canvas, generally speaking keep it under two.
Here are a couple values I found interesting:
r
= 0.6 shows how the points start to drift towards the verticesr
= 0.66 shows how that ultimately ends upr
= 0.4 shows the points starting to disperse throughout the triangler
= 0.33 shows a point when the full triangle can become filled inr
= 1.25 shows a repeated pattern starting to form outside the triangler
= 1.5 creates a nice looking snowflake fractal that incorporates the original triangle
Moving to N-Gons
A triangle isn't the only shapes this works for, in fact a chaos game can be used to create self similar fractals in any n-sided regular polygon, given the right scaling factor, with squares being the notable exception.
We will look at squares a bit later; however, the general issue is the geometry of a square makes it so the points generally fill in the square as opposed to creating fractal. In order to make fractal with a chaos game in a square we will either need to modify the rules of the game or add “additional vertices” the game can choose from.
The main trick to playing a chaos game with an n-gon is determining the proper value for r
such that the fractal appears.
There's a whole lot of math that has already been done to figure this out luckily, the explanation of which I don't feel
qualified (nor do I understand it enough) to explain, but the optimal r
value (r-opt
also called the kissing ratio Kn
)
can be calculated based on some modular math and trigonometry.
Wikipedia actually has a good breakdown of this and sites the sources for the papers that discuss the r-opt derivation under the Optimal value of r for every regular polygon section.
With these and a couple other helper methods to create an n-gon given the desired number of sides and choose a random point inside the n-gon, you can create an n-gon chaos game simulator.
Additional Vertices and Restricted Rule Sets
We've already explored what happens when we change the scaling factor, but we can also modify the vertices the points can jump toward. By altering the allowable destinations for the points, we introduce additional geometries to the polygon. In the case of a square, this variation provides enough variety to create fractals.
It was stated above, but never shown, that under the traditional chaos game rules, a square will just fill up with points.
There are a couple different ways we can change the vertices of the default square to help produce fractals.
The first is by including the center of the square with an r
value of 0.66
. Using this setup we see what's
called the Vicsek fractal.
Instead of including the center, we can include the midpoints of each side, with an r
value of 0.66
. This time we get what's
known as Sierpinsky's Carpet.
Another way to influence the game is by further restricting the ruleset. There are many ways to modify the chaos game, most of which involve introducing memory—imposing additional constraints based on the previously selected vertex. For example if we were to exclude the most recently selected vertex from the list of possibilities each iteration we would get:
An interesting aspect of restricting the ruleset is that these constraints can be applied to different shapes, leading to unique fractal structures. Consider the following restricted rule:
A point inside a square repeatedly jumps half of the distance towards a randomly chosen vertex, but the currently chosen vertex cannot neighbor the previously chosen vertex if the two previously chosen vertices are the same.
Implementing these rules with square gives a this gnarly looking fractal.
And if we instead use a pentagon instead of square, we get something crazier.
By adjusting which vertices points can move toward and adding rule-based restrictions, simple shapes can become intricate fractals. A square normally fills with points, but adding the center or midpoints creates structured patterns like the Vicsek fractal and Sierpiński's Carpet. Further refining the rules with memory constraints produces even wilder fractals, showing how small changes can dramatically shape the final pattern. Whether in squares, pentagons, or other polygons, these variations highlight the balance between randomness and order.
Beyond Polygons
This is just a small subset of what can be described as chaos games, and things get far more chaotic (sorry) when we move past polygons. Fractals like the Barnsley Fern and the Mandelbrot Set can also be understood through chaos games.
This rabbit hole runs deep, and while we didn't reach the bottom in this post, I hope you found it interesting and maybe gained a deeper appreciation for the seemingly random patterns in mathematics and nature. Chaos games show how simple rules can create intricate, self-organizing structures, bridging the gap between randomness and order. The deeper you explore, the more surprising and beautiful these systems become—whether in fractals, nature, or even real-world phenomena, chaos is everywhere, waiting to be explored.