Recently, I’ve been working with a psychology student interested in how our brains perceive fractal images in nature (trees, clouds, lanscapes, etc.). I dug up some old PostScript programs which reproduced images from The Algorithmic Beauty of Plants, which describes L-systems and how they are used to model images of plants. (Don’t worry if you don’t have the book or aren’t familiar with L-systems — I’ll tell you everything you need to know.)
To make matters concrete, I changed a few parameters in my program to produce part of a Koch snowflake.
The classical way of creating a Koch snowflake is to begin with the four-segment path at the top, and then replace each of the four segments with a smaller copy of this path. Now replace each of the segments with an even smaller copy, and recurse until the copies are so small, no new detail is added.
Algorithmically, we might represent this as
F +60 F -120 F +60 F,
where “F” represents moving forward, and the numbers represent how much we turn left or right (with the usual convention that positive angles move counter-clockwise). If you start off moving to the right from the red dot, you should be able to follow these instructions and see how the initial iteration is produced.
The recursion comes in as follows: now replace each occurrence of F with a copy of these instructions, yielding
F +60 F -120 F +60 F +60
F +60 F -120 F +60 F -120
F +60 F -120 F +60 F +60
F +60 F -120 F +60 F
If you look carefully, you’ll see four copies of the initial algorithm separated by turning instructions. If F now represents moving forward by 1/3 of the original segment length, when you execute these instructions, you’ll get the second image from the top. Try it! Recursing again gives the third image, and one more level of recursion results in the last image.
Thomas thought this pretty interesting, and proceed to ask what would happen if we changed the angles. This wasn’t hard to do, naturally, since the program was already written. He suggested a steeper climb of about 80 degrees, so I changed the angles to +80 and -140.
Surprise! You’ll easily recognize the first two iterations above, but after five iterations, the image closes up on itself and creates an elegant star-shaped pattern.
I was so intrigued by stumbling upon this symmetry, I decided to explore further over the upcoming weekend. My next experiment was to try +80 and -150.
The results weren’t as symmetrical, but after six levels of recursion, an interesting figure with bilateral symmetry emerged. You can see how close the end point is to the starting point — curious. The figure is oriented so that the starting points (red dots) line up, and the first step is directly to the right.
Another question Thomas posed was what would happen if the lengths of the segments weren’t all the same. This was a natural next step, and so I created an image using angles of +72 and -152 (staying relatively close to what I’d tried before), and using 1 and 0.618 for side lengths, since the pentagonal motifs suggested the golden ratio. Seven iterations produced the following remarkable image.
My purpose in writing about these “fractal” images this week is to illustrate the creative process in doing mathematics. This just happened a few days ago (as I am writing this), and so the process is quite fresh in my mind — a question by a student, some explorations, further experimentation, small steps taken one at a time until something truly wonderful emerges. The purist will note that the star-shaped images are not truly fractals, but since they’re created with an algortihm designed to produce a fractal (the Koch snowflake), I’m taking a liberty here….
This is just a beginning! Why do some parameters result in symmetry? How can you tell? When there is bilateral symmetry, what is the “tilt” angle? Where did the -24.7 come from? Each new image raises new questions — and not always easy to answer.
Two weeks ago, this algorithm was collecting digital dust in a subdirectory on my hard drive. A simple question resurrected it — and resulted in a living, breathing mathematical exploration into an intensely intriguing fractal world. This is how mathematics happens.
Almost a week has passed since writing the first part of this post, and a lot has happened since then. I began using the computer as a laboratory — that is, a way to collect data upon which to base a conjecture. My first line of exploration was the stars — I was intrigued by the fact that this recursive algorithm “closed up” when given certain parameters.
What was special about 80 and 140? The difference being 60 didn’t suggest much, since the difference was also 60 with the Koch curve. Their sum is 220? This happened to produce some surprising results; one of my first successes was using 45 and 175 to produce the following image.
Another attractive image was created using parameters of 205 and 15 degrees.
But that’s not the entire story — not every pair of angles which sum to 220 produces a star-like image. With 18 and 202, the curve doesn’t appear to close up — the following video clip shows the program running for about three minutes. As it runs longer and longer, more and more of the page is covered. Keep in mind this is not a random process — it’s the same process which produced the Koch snowflake, but with different starting parameters.
But what was special about 220? I don’t know yet — I’ve been spending my time exploring and not diving into the mathematics as yet. At lunch today, I thought about this some more — and wondered that if angles adding to 220 produced results, why not try 140? After all, 140 = 360 – 220. Remarkably, this also worked, and produced the following image. The angles used here were 65 and 75.
I hope you see what I’m getting at here — using the computer not only to produce neat images, but also perform mathematical experiments. Now that I’ve collected some data, it’s time to try and prove that these stars do in fact close up. Sure, they look like they close up — but any computer screen is pixellated, and so looks could be deceiving.
This especially becomes a problem with the 18 and 202 parameters. It may look like the algorithm fills more and more of the screen — but when literally tens of millions of line segments are computed and drawn, very small errors may accumulate. So seeing is, well, not believing — merely suggesting.
I’ll keep you updated on this project when I find new results, and I’ll continue to post new images I generate to @cre8math on Twitter. And if you create any interesting images using this algorithm, please comment below!