1. ## Fractal Generator

Hello,

As a small side project, I am going to have a go at makeing a Fractal generator using C++ and SDL.

I just wanted to check with somebody that knows about Fractals. Am I correct in my understand, that effectively I calculate a fractal function, such as f(z)=z^2+c. to give a number such as 4+5i, would the co-ordinates (if 4+5i is the answer) simply be x=4 and y = 5?

I know then, that I would simply feed that 4+5i back into the z parameter of the function and go again, and then colour each pixel depending on if the function ever leaves the screen and if so by how many iterations.

Thanks,

Darren.

2. Unusual question we don't usually see on cboard. Since you are dealing with complex numbers and you quoted the formula z(n+1) = z(n)^2 + C (where 'n' is an iteration index), I am assuming that you are attempting to recreate the Mandelbrot set or something similar to it?

To answer your question, if you have the number in the form a+bi, then the value 'a' represents your x coordinate and the 'b' represents your y coordinate, since you are basically plotting an Argand diagram. (By the definition of the Mandelbrot set, if that is indeed what you are trying to recreate, you plot the complex values of 'C' for which z(n+1) <= 2 as n approaches infinity. Although I don't have a clue if that is the fractal you intend to generate).

Edit: Out of curiosity, will you be using a mathematical library to deal with the complex numbers or will you be coding that yourself?

3. Hi,

And thanks for the response. The function is for the Julia Set, used for an example.
I was looking to allow the user to type in a fractal equation and then to parse that to obtain the x,y co-ordinates. Is there a library that can do this?

Also, is there a set formula that a fractal function has to follow? I am extremely new to them, but I thought it would be an interesting challenge to learn more and gain some new programming skills along the way.

Thanks again.

4. Exactly how you do this depends on the type of fractal you are considering. There are four general types:

1) Escape-time fractals (which includes the Julia Set)
2) Iterated function systems (e.g. the Cantor Set)
3) Random fractals (e.g. Random walks)
4) Strange attractors (Differential equations which contain chaos, e.g. Duffing Equation - I had to do some work on that one at university. It was quite dull to be honest, lol).

Exactly how you implement the fractals depends on the type of fractal you are considering, so if you are going to make a program which is able to generate more than one type of fractal you will have to have some way of specifying which type of fractal you are talking about.

In terms of parsing the mathematical expressions to then use in your program I would suggest googling some C++ libraries which offer parsing mathematical expressions. Here are a few I've found:
muParser - a fast math parser library
muParserX - A math parser library for C++ with support for arrays and strings
C++ expression parser

Although I remember reading a post on here a long time ago about doing it and I don't think it is too difficult if you implement a binary tree to keep track of the order of operations etc. Although taking a pre-written library to parse the expressions would probably be less work if you ask me, and your project has already got the potential to be big enough for the time being if you ask me.

Edit: Is this a homework project or just for academic interest?

5. Thanks again. I will have a read up on what you have advised.

It is a personal project more than anything. I am a University student, and I want to build up an online portfolio of work that I can include with job applications when I graduate (another 2 years yet). This will be my first piece to, hopefully, be included in the portfolio.