15.2 Iterated Fractals
This self-similar behavior can be replicated through recursion: repeating a process over and over.
Example 1
Suppose that we start with a filled-in triangle. We connect the midpoints of each side and remove the middle triangle. We then repeat this process.
If we repeat this process, the shape that emerges is called the Sierpinski gasket. Notice that it exhibits self-similarity – any piece of the gasket will look identical to the whole. In fact, we can say that the Sierpinski gasket contains three copies of itself, each half as tall and wide as the original. Of course, each of those copies also contains three copies of itself.
import numpy as np
import matplotlib.pyplot as plt
DEPTH = 5 # EDIT: try 0, 1, 2, 3, ... up to 7, and re-run each time
def sierpinski(tri, depth):
# At each step, replace the triangle with three half-size copies of itself.
if depth == 0:
return [tri]
a, b, c = tri
ab, bc, ca = (a + b) / 2, (b + c) / 2, (c + a) / 2
out = []
for corner in ((a, ab, ca), (ab, b, bc), (ca, bc, c)):
out += sierpinski(np.array(corner), depth - 1)
return out
start = np.array([[0.0, 0.0], [1.0, 0.0], [0.5, np.sqrt(3) / 2]])
triangles = sierpinski(start, DEPTH)
fig, ax = plt.subplots(figsize=(6.2, 5.4))
for t in triangles:
ax.fill(t[:, 0], t[:, 1], color="#1f4e79", linewidth=0)
ax.set_aspect("equal")
ax.axis("off")
ax.set_title(f"Sierpinski gasket, step {DEPTH}", fontsize=13)
plt.show()
print(f"{'step':>5}{'triangles left':>16}{'= 3^step':>10}{'area kept':>12}{'removed so far':>16}")
for k in range(DEPTH + 1):
area = 0.75 ** k
print(f"{k:>5}{3 ** k:>16,}{'3^' + str(k):>10}{area:>12.5f}{1 - area:>15.2%}")
print(f"\nat step {DEPTH} the picture is {len(triangles):,} solid triangles, each "
f"1/{2 ** DEPTH} as wide as the original")
print("each step keeps 3 of 4 sub-triangles, so the area is multiplied by 3/4 every time")
print("push DEPTH up and the area heads to 0, but the picture never becomes empty")
We can construct other fractals using a similar approach. To formalize this a bit, we’re going to introduce the idea of initiators and generators.
Note
Initiators and Generators
An initiator is a starting shape A generator is an arranged collection of scaled copies of the initiator
To generate fractals from initiators and generators, we follow a simple rule:
Note
Fractal Generation Rule
At each step, replace every copy of the initiator with a scaled copy of the generator, rotating as necessary
This process is easiest to understand through example.
Notice that the Sierpinski gasket can also be described using the initiator-generator approach
Using iteration processes like those above can create a variety of beautiful images evocative of nature[2][3].
More natural shapes can be created by adding in randomness to the steps.
The landscape below was created using fractals, then colored and textured.
[1] http://www.flickr.com/photos/visualarts/5436068969/
[2] en.Wikipedia.org/wiki/File:Fr...e_b_-_2%29.jpg
[3] en.Wikipedia.org/wiki/File:Ba...-_4_states.PNG
[4] en.Wikipedia.org/wiki/File:Fr...lLandscape.jpg
Adapted from Math in Society by David Lippman, hosted on LibreTexts (math.libretexts.org) and licensed under CC BY-SA 3.0. Changes were made. License: CC-BY-SA-3.0 .