Fractal Fun!

JimCamel
10-03-2003, 02:01 AM
Who loves fractals? YOU DO!

As I'm sure you all know, Fractals are images which have recursive nature, that the same shape is repeated no matter how far you zoom in. For example, a simple line is made up of smaller lines which are made up of smaller lines, and so on till infinity.
Typically these fractals are generated by recursion, creating the image by creating all the sub images.However, as we all know, recursion can be costly.
The method demonstrated in this code example uses another method, known as a Random Iteration Algorithm. The idea is that we start with a single point, and some Affine Maps, which are essentially 2D Transformation matrix.
We assign each Affine Map a probability, and choose a random map based on these probabilities. We then apply this transfomation on our point, and redraw it. This continues on for a specified number of points.
This approach has certain mathematical properties. Because of these maps and The probabilites we assign to them, we get what is known as an "Attractor", which is the fractal. All these points will converge to form our fractal, even though they are generated by random numbers. Any point within our attractor, when transformed using one of these Affine Maps will also be in an attractor. As my graphics lecturer said, these attractors are in some ways similar to black holes, in that all the points converge within them.

If you've read all of that, congratulations. If you understood any of it, you're a genius :p .

But anyways, here's some code I wrote which demonstrates how to create these Randomly Iterated Fractals. If you come with any cool Affine Maps, I'd love to see them.

OnErr0r
10-03-2003, 04:02 AM
I really do Jim (love fractals). :)

That's exactly what I needed at 3AM. Dogs woke me up so I think I'll stay up.

JimCamel
10-03-2003, 07:47 AM
Okay, here's one for OnError (and anyone else who may be better at computer science than maths).

This is the second of my two Fractal demos. The first, with Random Iterated Fractal Attrator, was some pretty crazy maths and geometric theory. Well this one deals with some pretty crazy Computer Science concepts, namely, Grammars!
Now these ain't your english teachers grammar, in computer science we use these to define languages, including defining programming languages. A grammar basically consists of Terminals and Non-Terminals. A Terminal is like an end point, that's where the grammar actually turns into something useful, like a programming language command. A Non-Terminal is something which can derive other terminals and non-terminals. The Syntax is generally written
S-> F
F-> x
Where S and F are non-terminals, and x is a terminal. If we follow the derivation tree of S, we find S->F->x, so our final output string is x. But enough of the theory, lets see how this relates to fractals.

As I mentioned before, a fractal is a recursive image, such that zooming in on any part we will see a copy of the original image. Because non-terminals can lead to other non-terminals, we can define recursive behaviour simply by getting a non-terminal to lead to itself, ie.
S-> F
F-> xFx
When we derive it, we get S->F->xFx->xxFxx->xxxFxxx to infinity. Most normal Grammars have some sort of terminating point, but since this is a fractal, and therefore infinite, there will never be a termination. However since computers don't deal with calculations to infinity that well, we need to specify an order, which basically says after how many derivations to stop.

So how do we draw fractals then? Well, in fractals, we have 5 commands. The - terminal means rotate right a certain amount, the + terminal means rotate left a certain amount. The F non-terminal means move forward, drawing a line as we go (So far this is exactly like turtle graphics). The final two commands are the [ terminal, which means take the current state of our drawing vector/turtle (that is, X-coord, Y-coord, and direction), and push it onto a stack, and the ] terminal, which pops it back off the stack and sets our vector/turtle to it.

For more info, check out the code, it has more comments and a few examples with it. Once again, if you have any cool grammars, email me or post them here.

PS. Yes, I am bored.

OnErr0r
10-03-2003, 11:48 PM
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFabulous! ;)

Tristan
10-04-2003, 12:04 AM
Awesome. I can't believe how short the code is to make something so cool. :D

Mathimagics
10-06-2003, 07:36 AM
Example 1 is an "Affine Transformation" fractal, and I think the 2nd one is called an "L-system"???

My avatar is a scaled-down copy of a "symmetric icon", (cf Field/Golubitsky, "Symmetry and Chaos")

:cool:

JimCamel
10-06-2003, 05:15 PM
Correct on both counts Dr Memory. I thought you might appreciate them.

Mathimagics
10-06-2003, 05:32 PM
Yes Indeed!

Fractals across the Tasman ;)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum