Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tararoys
Last active May 26, 2021 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tararoys/45685f5b2c3536033e651cadf486734a to your computer and use it in GitHub Desktop.
Save tararoys/45685f5b2c3536033e651cadf486734a to your computer and use it in GitHub Desktop.

How Fractal Flames Are Made: An Introduction To Multiple Reduction Copy Machines

Both Apophysis and Chaotica creates a style of fractal called a fractal flame.

A fractal flame is a form of generated art created by an iterated function system. The name might sound scary, but once I stop using big words and start showing pictures, it becomes much easier to understand what is going on.

There are two methods for creating fractal flames.

I love each of these methods. They are mathematically fascinating, they let me get into all sorts of interesting and artistic philosophical debates about order versus chaos, and I I am fascinated by the way these two wildly different methods create exactly the same result.

Let me repeat that: both of these methods create exactly the same result.

By the end of these two tutorials, I hope to infect you with the same level of awe and excitement that I feel when considering these two methods. Or, if you don’t share the awe, at least you'll get an inkling as to exactly why I think iterated function systems are amazing.

The first method is called the Multiple Reduction Copy Machine algorithm.

Part of the reason it's called that is that you could literally do this method on a physical copy machine with enough paper, time, and nobody breathing down your neck about wasting ink, paper, or time.

As you'll see in this tutorial, this method is extremely organized, very systematic, and very slow.

It's biggest advantage is also the reason why I put this tutorial first: when I was starting out, I thought it was the easiest way to visualize what was going on when designing a flame fractal.

The second method is called the Chaos Game, and it is extremely disorganized, completely chaotic, and extremely fast.

It's biggest advantage is its speed, which is why both Apophysis and Chaotica use it instead of the Multiple Reduction Copy Machine method to create fractals.

However, a lot of people like me, when they first encounter the chaos game, become confused about how it could possibly work. That was the case when I started out, so I taught myself the Multiple Reduction Copy Machine method first. And that's why I am teaching it first to you.

That being said, both methods create exactly the same result.

So what is the multiple reduction copy machine method? Allow me to demonstrate.

Pictured is a blank white square.  A mouse cursor draws a dark black squiggle in the center of white square.  If you imagine a child scribbling aimlessly with a pen, that's pretty much what is going on: the lines don’t form a picture or words or anything. It more or less looks like someone dropped a black spaghetti noodle in the center of the page. It's just an animation of someone drawing a random black squiggle in the center of a white sheet.

When operating a copy machine, it helps to have something to copy. Above, I'm making a random black squiggle on a white background so that I have something to copy.

In this animation, I am going to copy the black squiggle I made, shrink it down, and make it smaller.  Since you're reading this alt-text, though, let me go for a different demonstration that involves different senses than sight.   Imagine that I am starting with an regular sized apple, the kind you would buy in a grocery store.  This apple is placed in the center of a one-foot by one-foot cloth napkin.  The an apple the size of my fist and would fit comfortably in my hand.  Now imagine that an exact copy of that apple is made.  This apple is an exact copy except for two differences.  First, instead of being the size of my hand and fitting comfortably in my palm, it is the size of a crabapple or a golf ball.  Second, instead of being positioned in the center of the napkin, I position this apple halfway between the original apple in the cenrt of the napkin and the lower left corner.   TAgain, The original apple and the copy are the same in every respect except the copy is half the size of the original, and the copy is positioned halfway between the center of the napkin and the lower left corner of the napkin instead of being a full sized apple in the center of the napkin.

In the above, I am running the original drawing through a copy machine. That copy machine shrinks the image down by half and moves it to the lower left corner of the white square. This shrinking and moving is called a transformation.

Continuing with the apple analogy, in this animation, the original apple is still in the center of the one foot by one foot square napkin. There is a half-sized copy of the original apple in the lower left corner square.  This animation demonstrates another copy of the original apple being shrunk and moved to the upper left hand corner.  If you pretend is an apple placed in the center of the white square napkin, and then imagine grabbing a copy of that Apple, having it magically shrink down in your hand, and then placing it in the upper left hand corner of the white square napkin, it is essentially the same idea: the original apple has been transformed into a smaller copy in a different place.

Since this is the multiple reduction copy machine method, it's time to build up the second copy machine. This one makes a copy of the original drawing, shrinks it, and place is it in the upper left hand corner of my square.

Continuing with the apple analogy, this animation shows a white square with a large apple in the center, a half-sized apple in the lower left corner, and a half-sized apple in the upper left corner.  In this animation, we make a third half-sized apple and place it in the upper right hand corner, halfway between the center of the napkin and the upper right hand corner of the napkin.  I now have a fist-sized apple in the center of the napkin and three crabapple or golf-ball sized apples: one in the lower left corner, one in the upper left corner, and one in the upper right corner.

With this multiple reduction copy machine method, I have taken my original drawing and run it through three reduction copy machines. I am left with three smaller copies of my original drawing arranged in a triangle.

Continuing with the apple analogy, I now have a large apple in the center of the napkin and three smaller apples postioned in a triangle, one in the lower left corner, one in the upper left corner, and one in the upper right corner.  I reach in, take the big apple, and make it disappear.  (either eat it or toss it to the birds.)   I am left with just the three smaller copies of the original apple.  What I have done is run one iteration of the multiple apple copy reduction machine- I took one apple, made three reduced-size copies of the apple, and got rid of the original apple.

So are multiple reduction copy machine has created three copies and deleted the original. These three copies form a new image. What if we took that new image and ran it through the multiple reduction copy machine again? And again? And again?

This is an animation showing what happens when do you run the same image through a multiple reduction copy machine several times.  It starts on the second iteration, when you have three crabble sized apples arranged in a triangle on a one foot by one foot napkin.  Following the same copying process outlined above,  everything on the napkin is run through the Multiple Reduction Copy Machine. This means that one copy of the crabapple-sized apples arranged in a triangle is made, shrunk down, and positioned in the lower left corner, such that you now have a triangle of three thumb-sized apples in the lower left corner.  Another copy is positioned in the upper left corner, such that you now have a triangle of three thumb-sized apples in the upper left corner.  Another copy is positioned in the upper right corner, such that you now have a triangle of three thumb-sized apples in the upper right corner.  The original three crabapples are removed from the napkin, leaving only the three half-sized copies of the three crabapples, which ends up looking like nine thumnail sized apples arranged in a triangle.  This is the second iteration of the multiple copy reduction machine.  Starting the third iteration, the whole napkin is again copied three times, leaving behind a triangle that consists of twenty-seven thumtack sized apples arranged in a triangle.  Starting with the fourth iteration, the whole napkin is again copied and reduced three times, leaving behind a triangle that consists of 81 pinhead sized apples.  Starting the fifth iteration, The whole napkin is again copied and reduced three times, leaving behind a triangle that consists of 243 pinpoint sized apples.  At this point, the apples are too tiny to really feel if we keep shrinking them, so we can stop iterating.  Fractals, in theory can go on forever, but as a practical matter there is no point in continuing the copying process beyond the point that a human can feel a difference wehen running their fingers over the pattern made by 243 poinpoint sized apples arranged in a triangle.  At this point, what started out as one large, fist-sized apple has been reduced to a triangle pattern of poinpricks that feels like a a large triangle made of three smaller triangles, and each of those three smaller triangles is made of three smaller triangles, and so on down until one can no longer feel the difference.

This creates a fractal called Serpinski's Triangle.

#Part 2: The Chaos Game!

So this is how Fractal flames are made...kind of. Sort of. While, in theory, you could make a fractal this way, no program ever does. Because it's slow. Slow enough that for certain fractals, the universe would end before you got a likeable result. The key bit about the above method is that it is very ordered. It is extremely easy to see, after a couple of steps, things are going. There's nothing chaotic about it at all. Not so with the Chaos game.

But let's see what sort of fun we can have with the multiple copy reduction machine- and take it apart- and magically metamorphose it Until, like a caterpillar turning into a butterfly, It becomes the mysterious, much admired and very badly understood Chaos Game.

01AttractorsStartWithAnythingEndUpSerpinski

As we saw from the animations above, you can start with anything. You can start with a squiggle. You can start with a triangle. You can start with an abstract mountain. You can even start with a dot!

02GiveNumbersToEveryTransform

What if I start with some numbers? These numbers are veeery interesting. Let me illustrate they are interesting!

03HighlightingPoint21322

If I copy those numbers, just like I copied every other image, I will get the serpinski's triangle, like usual. But...let's look at each step! The first step divides the triangle into three zones: zone 1, zone 2, and zone 3 So...what If I said "Im interested in zone 2?" I highlight that in red.

I descide to say what zone I picked at the bottom. I picked zone 2, so I put the nubmer 2 at the bottom of the image, all the way to the left.

Now, on the second step, let's look into zone 2. It is also divided into three zones. I've decided, why not? Let's higlight that 1 in zone 2. And go to the bottom and stick a one right next to the 2.

So, on each step, each zone gets subdivided into three other zones. And I just pick one...whichever one I fancy. And at the bottom, I keep a record of whatever zone I picked. This is getting a trifle confusing...so let me picture it a different way:

04HighlightingPoint21322anotherway

The largest number is the first number, the second largest number is the second number, the third number is the third number, and so on... 21322

05HighlightingPoint21322DrawingThePath

So...I've been shrinking numbers, and I've been shrinking images...but what if I just started with a point?

06HighlightingPoint21322JustThePath

Ok, the point, unlike the number, is staying the same size. Why? Because numbers shrink, but mathematically a point is just a dot. You can't change the size of a dot. So there's no point in 'shrinking' it.

07HighlightingPoint21322JustTheResult

and...let's get rid of the points and just keep the last one. And, hey! That point landed right on the serpinki's gasket. And right in the place I expected it to, based on the location scheme from this image:

03HighlightingPoint21322

Great. So I've sucessfully stuck one point on the Serpinski's triangle. What If I stick a couple more points on it?

08HighlightingPoint12132TransformingPoint21322WithTransform1

09HighlightingPoint11213byTransformingPoint12132WithTransform1

Ok, now let's line all three of these up side by side, and I can see that i have three points. in three different places on the triangle.

10ThreePointsOnTheAttractor

What If I stuck those three points on the same image?

11CombineTheThreePointsOntoASingleFractal

Ahah! And now, we see that I didn't just pick those three location by accident.

Look at those location codes.

To make a new location code, I dropped the right-most number and added a new number to the left. Remember how, the left most digit is the biggest, and the right one is the smallest? The left number has the biggest influence on the locaion of the point, and the right one has the smallest.

You can see this illustrated here:

SerpinskisGasketUniqueAddresses

So...how do I pick which transform to add? How do I pick the next big thing to tack onto the left side? WITH CHAOS! RANDOMLY! We have now gotten to the bit where we've turned into the chaos game! I know that I can represent every point on my 'fractal space' with a five digit 'location code' sort of like a postal 'zip code.' I I just stick the numbers 1, 2, 3 in a hat, and pull one out to see what transform I should stick on the left hand side next.

12AsequenceOfRandomlyAppliedTransformsWillFindEveryAddressOnTheFractal

Every time I apply a transform I draw a dot The thing about drawing these numbers random Is that it's like one giant long tape, But that tape will include every five digit location code on the fractal Which means that my traveling point will visit every location code on the fractal It'll bounce around a lot, sure, it'll bounce around reaaallly chaotically but it will always end up visiting every location as long as you give it enough time. And as long as I draw a dot at the location it visited I will have drawn the fractal! https://user-images.githubusercontent.com/1163925/117889521-4d252900-b279-11eb-8760-e4643446fa56.gif And that is how you can turn this very top-down, orded method of making a fractal-

Into a system where you ricochet around from location to location like a hyperactive toddler, https://www.youtube.com/watch?v=IGlGvSXkRGI

And still end up with exactly the same result Except everyone uses the toddler. Why? Because the toddler is faster.

A lot faster.

So yes, you could do things in a very top-down, heirarchical, ordered way- a way that works, and is also very slow....

Or you could do things completely chatoically, but following a couple fo simple rules, and get the same exact result- but faster. And that's how you can transform a slow, orderly algorithms in to a quick, chaotic algorithm.

And that is how fractals are made.

@tararoys
Copy link
Author

01AttractorsStartWithAnythingEndUpSerpinski
02GiveNumbersToEveryTransform
03HighlightingPoint21322
04HighlightingPoint21322anotherway
05HighlightingPoint21322DrawingThePath
06HighlightingPoint21322JustThePath
07HighlightingPoint21322JustTheResult
08HighlightingPoint12132TransformingPoint21322WithTransform1
09HighlightingPoint11213byTransformingPoint12132WithTransform1
10ThreePointsOnTheAttractor
11CombineTheThreePointsOntoASingleFractal
12AsequenceOfRandomlyAppliedTransformsWillFindEveryAddressOnTheFractal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment