Skip to content

Commit d58f577

Browse files
authored
adding draft of Barnsley fern chapter (#811)
* adding draft of Barnsley fern chapter * adding appropriate video link
1 parent 442a170 commit d58f577

19 files changed

+279
-29
lines changed

SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [Plotting](contents/plotting/plotting.md)
77
* [Domain Coloring](contents/domain_coloring/domain_coloring.md)
88
* [Iterated Function Systems](contents/IFS/IFS.md)
9+
* [The Barnsley Fern](contents/barnsley/barnsley.md)
910
* [Data Structures](contents/data_structures/data_structures.md)
1011
* [Stacks and Queues](contents/stacks_and_queues/stacks_and_queues.md)
1112
* [Mathematical Background](contents/mathematical_background/mathematical_background.md)

contents/IFS/IFS.md

+43-29
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ A few quick notes before we start:
66
That is to say that the code presented in this chapter will output another file that can be easily plotted by an external plotter.
77
If you like to use a plotter provided by your language of choice, please modify the code provided to do so.
88

9-
2. This chapter is currently a subsection to the plotting chapter, but we may extend the algorithm archive in the future with other fractal generation methods, which would require created a new section on fractals, in particular.
9+
2. This chapter is currently a subsection to the plotting chapter, but we may extend the algorithm archive in the future with other fractal generation methods, which would require creating a new section on fractals, in particular.
1010
This would include a chapter with more rigorous definitions on fractals, which is largely missing from the following discussion.
1111
Please let us know if you are interested!
1212

13-
In this chapter, we will show you how to make one of the most famous fractals via Iterated Function Systems (IFSs): the Sierpinski triangle.
13+
In this chapter, we will show you how to make one of the most famous fractals, the Sierpinski triangle, via Iterated Function Systems (IFSs).
1414
We will also introduce a number of interesting concepts for further exploration, such as chaos games, Hutchinson operators, and attractors.
1515

1616
## The Sierpinski Triangle
1717

18-
To begin the discussion of Iterated Function Systems (IFSs), we will first discuss what might be one of the most famous fractals currently known, the Sierpinski triangle, shown below:
18+
To begin the discussion of Iterated Function Systems (IFSs), we will first discuss what might be one of the most famous fractals currently known: the Sierpinski triangle (shown below):
1919

2020
<img class="center" src="res/IFS_triangle_1.png" alt="Sierpinsky Triangle Chaos Game" style="width:100%">
2121

2222
This image is clearly a set of triangles embedded in a larger triangle in such a way that it can be continually cut into three identical pieces and still retain its internal structure.
23-
This idea is known as self-similarity {{"self-similar" | cite }}, and it is usually the first aspect of fractals that will catch an audience's attention.
23+
This idea is known as self-similarity {{"self-similar" | cite }}, and it is usually the first aspect of fractals to catch an audience's attention.
2424
In fact, there are plenty of uses of fractals and their mathematical underpinnings, such as estimating the coastline of Britain {{ "mandelbrot1967long" | cite}}, identifying fingerprints {{ "jampour2010new" | cite }}, and image compression {{ "fractal-compression" | cite }}{{ "saupe1994review" | cite }}.
2525
In many more rigorous definitions, a fractal can be described as any system that has a non-integer Hausdorff dimension {{ "3b1bfractal" | cite }}{{ "hausdorff" | cite }}{{ "gneiting2012estimators" | cite }}.
26-
Though this is an incredibly interesting concept, the discussion of this chapter will focus primarily on methods to generate fractal patterns and will refrain from delving into this discussion for now and instead focus on the methods by which fractals can be generated through IFSs.
26+
Though this is an incredibly interesting concept, the discussion of this chapter will instead focus on methods to generate fractal patterns through iterated function systems.
2727

2828
To start, imagine creating a triangle from three points, $$A$$, $$B$$, and $$C$$.
2929
These points can be arbitrarily chosen, but for this conversation, we will constrict them to the vertices of an equilateral triangle, as shown below:
@@ -40,7 +40,7 @@ f_3(P) &= \frac{P + C}{2}\\
4040
\end{align}
4141
$$
4242

43-
Each function will input a particular location in space (here, $$P \in \mathbb{R}^2$$) and output a new location that is the midpoint between the input location and $$A$$, $$B$$, or $$C$$ for functions 1, 2, and 3 respectively.
43+
Each function will read in a particular location in space (here, $$P \in \mathbb{R}^2$$) and output a new location that is the midpoint between the input location and $$A$$, $$B$$, or $$C$$ for $$f_1$$, $$f_2$$, and $$f_3$$ respectively.
4444
The union of all of these functions (the set of all possible functions available for use) is often notated as the _Hutchinson operator_ {{ "hutchinson-operator" | cite }}{{ "hutchinson1981fractals" | cite}}, and for this case it would look like this:
4545

4646
$$
@@ -63,7 +63,7 @@ From here, each new point ($$D$$, $$E$$, and $$F$$) will spawn 3 children, and e
6363
</div>
6464

6565
Here, all red children come from $$D$$, green children come from $$E$$ and blue children come from $$F$$.
66-
From here, the children will then spawn 3 more children, each of which will move according to a different function.
66+
At this stage, the children will then spawn 3 more children, each of which will move according to a different function.
6767
Those children will then spawn more children, who act accordingly.
6868
As this process continues on and on, we begin to see an interesting pattern form:
6969

@@ -77,11 +77,11 @@ As this process continues on and on, we begin to see an interesting pattern form
7777
This is the Sierpinski triangle.
7878
At first, it might seem like mathematical magic that a simple set of 3 functions can create such a pattern.
7979
After all, why aren't any of the children migrating to the empty spaces in the structure?
80-
This will require some thought, but the simplest answer is that no function within the Hutchinson operator allows for children to enter those spaces.
80+
This will require some thought, but the simplest answer is that no function within the Hutchinson operator allows for children to enter those spaces; therefore, none of the children can enter them.
8181

8282
## What about a square?
8383

84-
When I learned about this for the first time, I began to wonder about other shapes.
84+
When I learned about how the Sierpinski triangle could be generated from 3 simple functions, I began to wonder about other shapes.
8585
Could we create fractal squares? Hexagons? Circles?
8686
Such shapes _seem_ like natural extensions to the triangular Hutchinson operator provided above, but there's a bit of a hitch...
8787

@@ -109,20 +109,24 @@ If we then create 5 initial points located between all the vertices and allow th
109109
</video>
110110
</div>
111111

112-
Well, this is essentially a square of squares.
112+
We essentially see a square of squares.
113113
What happened to the self-similar structure we were getting before?
114114
Why isn't this more interesting?
115115

116116
The best answer I have for now is that some Hutchinson operators are interesting and some are not.
117-
On the other hand, this square is a bit more interesting than it first appears, but I think this is easiest to understand when we use the Hutchinson operator in a slightly different way.
117+
Still, this square is a bit more interesting than it first appears, but to see why, we need to use the Hutchinson operator in a slightly different way.
118118

119119
## Chaos games and attractors
120120

121-
Until now, we have been using the Hutchinson operator in a computationally costly way.
121+
Until now, our visualizations for both the Sierpinski triangle and the square have been computationally costly.
122122
Every iteration, we generate 3 or 4 new children per child per step of the simulation.
123123
This scales exponentially and means that we will quickly have millions of children to keep track of!
124+
In fact, to deal with this, we developed our own method of counting through the tree to more efficiently keep track of everything, but that is a story for another day.
124125

125-
A much more computationally feasible method to use the Hutchinson operator comes in the form of the _chaos game_ {{ "chaos-game" | cite }}{{ "chaos-game-wolf" | cite }}.
126+
The question for now is whether there is a more computationally feasible way of iterating through our Hutchinson operator.
127+
128+
As it turns out, there is!
129+
Rather than keeping track of every possible movement within the Hutchinson operator to draw out a shape, it's actually possible to randomly sample the function set instead through a process known as a _chaos game_ {{ "chaos-game" | cite }}{{ "chaos-game-wolf" | cite }}..
126130
Here, instead of tracking children of children, we track a single individual that chooses randomly between the Hutchinson functions, as shown here:
127131

128132
{% method %}
@@ -138,7 +142,7 @@ Here, instead of tracking children of children, we track a single individual tha
138142
[import:4-16, lang:"coconut"](code/coconut/IFS.coco)
139143
{% endmethod %}
140144

141-
If we set the initial points to the on the equilateral triangle we saw before, we can see the Sierpinski triangle again after a few thousand iterations, as shown below:
145+
If we set the initial point to the on the equilateral triangle we saw before, we can see the Sierpinski triangle again after a few thousand iterations, as shown below:
142146

143147
<div style="text-align:center">
144148
<video style="width:100%" controls>
@@ -147,13 +151,14 @@ If we set the initial points to the on the equilateral triangle we saw before, w
147151
</video>
148152
</div>
149153

150-
That said, there is something peculiar about the way the chaos game starts.
151-
Essentially, our lone child begins their journey at a random location.
152-
What if that location is off the triangle?
153-
Well, let's test that!
154+
Here, we are plotting 200,000 point locations in sets of 1000, and every set becomes successively more blue as the visualization continues.
155+
At first glance, this visualization seems bewildering.
156+
After all, it appears as if the entire triangle just magically comes into view in a few seconds.
157+
The important thing to remember here is that each of these 200,000 dots is another location that our initial point decided to visit.
154158

155-
If we start the point at the center of the triangle, it will eventually find its way onto the triangle, and then all subsequent iterations will be on the fractal.
156-
Here, I have plotted the first 20 steps where the wanderer is still looking for the correct shape:
159+
That said, there is something peculiar about the way the chaos game starts.
160+
We are actually allowed to start the simulation *off* of the Sierpinski triangle.
161+
As we mentioned earlier, none of the functions for the Sierpinski visualization allow children to enter the empty spaces of the triangle, so let's see what happens if we start the point off at the center of the triangle:
157162

158163
<div style="text-align:center">
159164
<video style="width:100%" controls>
@@ -162,17 +167,26 @@ Here, I have plotted the first 20 steps where the wanderer is still looking for
162167
</video>
163168
</div>
164169

165-
It would seem that the wanderer is _attracted_ to the Sierpinski triangle with this set of functions.
166-
That is actually the case.
167-
The truth is that the word _attractor_ is a very loaded term in the literature, but for the purposes of our discussion here, the _attractor_ is any shape defined by the iteration through Hutchinson operator functions.
170+
Here, I have plotted the first 20 steps of the chaos game, and it is clear that the point gets closer and closer to the triangle each iteration.
171+
Once it lands on the triangle, it can no longer escape and every movement from then on will be on the triangle.
172+
173+
In a sense, the wanderin point is _attracted_ to the Sierpinski triangle with this set of functions, and that is actually the case!
174+
The truth is that the word _attractor_ is a very loaded term in the literature, but for the purposes of our discussion here, an _attractor_ is any shape defined by the iteration through Hutchinson operator functions.
168175

169-
So let's go back to the square, which seemed like a somewhat random distribution of points:
176+
So let's go back to the example with the 4 points along the square and generate the attractor via a chaos game instead of going through every branch of the Hutchinson operator.
177+
If we do this, we get what seems to be a random distribution of points:
170178

171-
<img class="center" src="res/IFS_square_2.png" alt="Hutchinson square" style="width:100%">
179+
<img class="center" src="res/IFS_square_3.png" alt="Hutchinson square" style="width:100%">
172180

173-
Even with the chaos game, this will not change; however, we now know that the random distribution isn't truly random.
174-
Rather, it's an attractive plane where our lone wanderer can exist happily within.
175-
That is to say, the 2-dimensional square is, itself, the attractor for that Hutchinson operator, and if we start our journey person off of the square, they will eventually find themselves within it, similar to the triangle before.
181+
This kinda boggled my mind a bit when I looked at it for the first time.
182+
What does a random distribution of points mean in this context?
183+
184+
Well, firstly, it's only a random distribution between the square vertices of $$A$$, $$B$$, $$C$$, and $$D$$, but nothing exists outside of these points.
185+
This means that it's not actually a random distribution of points, but instead an attractive plane that our lone wandering point can exist happily within.
186+
187+
This really helped me understand how attractors present themselves in different dimensions.
188+
The Sierpinski triangle seems like a series of lines (one-dimensional objects) in two-dimensional space, but the square is a truly two-dimensional object.
189+
In general, this means that an attractor embedded within $$\mathbb{R}^N$$ can be any shape of dimension N or lower.
176190

177191
The next obvious question is whether a square can create any more interesting fractally patterns, and the answer is "yes, but only if we restrict the movement a bit."
178192
Which brings us to another topic entirely: restricted chaos games.
@@ -183,7 +197,6 @@ If you are interested, please let me know and I will be more than willing to add
183197

184198
Here is a video describing iterated function systems:
185199

186-
187200
<div style="text-align:center">
188201
<iframe width="560" height="315" src="https://www.youtube.com/embed/nIIp-vo8rHg"
189202
frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; pic
@@ -238,6 +251,7 @@ The text of this chapter was written by [James Schloss](https://github.com/leios
238251
- The image "[IFS triangle 5](res/IFS_triangle_5.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
239252
- The image "[IFS square 1](res/IFS_square_1.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
240253
- The image "[IFS square 2](res/IFS_square_2.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
254+
- The image "[IFS square 3](res/IFS_square_3.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
241255
- The image "[Chaos 1](res/chaos_1.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
242256
- The image "[Chaos 2](res/chaos_2.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
243257
- The video "[IFS triangle video 1](res/IFS_triangle_vid_1.mp4)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).

contents/IFS/res/IFS_square_3.png

2.44 MB
Loading

0 commit comments

Comments
 (0)