Fractals

Started by
10 comments, last by koji187 21 years, 12 months ago
Hi if any of you guys remember sonique an mp3 player,well there was 1 plugin for it where it was a tunnel effect with a fractal (a julia set) was displayed that was moving changing size and shit it was real fast, i want to know how can i generate fractals on the fly? that 1 seemed way too good to be true and can anyone here tell me the formula for generating a julia set? don''t worry im fimilier with complex algebra
Advertisement
Hm.
I have a book on programming fractals;
What it says about Julia sets is that the Mandelbrot set is a map for all possible Julia sets.

This is the Mand. equ.

Zn+1 = Zn^2 + C

Real components in the solution are used as the X values
Imaginary are the Y.


Different Cs produce different sets.

I don`t know how real-time fractal generation would work, but what I would do is have a separate thread rendering to the back buffer, and each time it had completed the render, I would flip the buffers. The amount of change from one frame to the next would depend on the framerate.
That way when framerate was slow, it would move slowly and not jerk.
When framerate was fast, it could move fast and be smooth.
At least, that has been my idea for good-looking fractal animation. :D

Bugle4d
~V'lionBugle4d
quote:
Zn+1 = Zn^2 + C


The C is the point in the complex plane.

I''d write it like this to avoid confusion:

Z[n+1] = (Z[n])^2 + C

Since the n+1 just mean that its the Z is the next in the row/array in the recursion.

Im not sure if you know or not, but to get the famous mandelbrot you need to calculate C values from -2.1 to 2.1 (same in imaginary an real values) And to check if it converge or not you can for example check if |Z[n]| > 2.0 , until n = 500, if its absolute value hasent gotten larger than two by then its safe to assume that it converges.

(ok I wrote a throughout explanation in an earlier thread, just search for that if you are wondering about something)



Anyways, to make fractals realtime is possible, but they cant be very detailed. Unless you could manage to find an explicit solution to the recursion (im not sure if it is possible)




(There is no border around this image)
ok guys thanks for the reply
but it seems i can''t graph that function on the display :S

i dont know how to do it correctly, the values just go from 0 to 30000 , any ideas?

and what does c equal for a julia set?
Say you pick a point in the graph...

C = (1.5, -2.3i)
A = C

then loop until |C| < limit
A = A^2 + C
loop
if( |C| < limit )
drawpoint()

Of course, the distance may never reach limit, so you have to add a counter that counts how many time the loop has been through...

Remember, that squaring a complex number is a little different from a normal:

(1+i)^2 = 1^2 + 2i + i^2 = 1 - 1 + 2i = 2i
delete this;
quote:
C = (1.5, -2.3i)
A = C

then loop until |C| < limit
A = A^2 + C
loop
if( |C| < limit )
drawpoint()


not entirely correct, here you modify A, but check |C|, you should check |A|

Here is the explanation I wrote in an earlier post:


      // the complex numbers used in the recursion equationComplex Z[2]; //[edit; corrected a typo]Complex P; // P is the point in the plane// Saving the values as a colorColor result[256][256];// Then define the area in the complex plane that should be rendered// The mandelbrot looks great in the interval:double start_x = -2.0;double end_x = 2.0;double start_y = -2.0;double end_y = 2.0;P.a = start_x; // the real part of P denoted as aP.b = start_y; // the imaginary part of P denoted as b// assigning the distance between each point (end - start = 4)double add = (4.0 / 256.0);// Starting a loop that goes through each of the 256*256 pointsfor(int x = 0; x < 256; x++){  for(int y = 0; y < 256;  y++)  {    //ok, a recursion equation is just basically a row of numbers    //where each of the numbers are a product or sum of some of    //the previous numbers and/or constants    //The mandelbrot fractal are generated out of a recursion    //equation where Z[n] = (Z[n-1])^2 + P, basically what this    //sayss is that each number is equal to the previous one in    //the row to the power of two plus P (P is the point in the    //plane)    //Since we dont have an infinite row of Z's to use we just    //recycle the ones we declared earlier    //The key point of this is to check if therecursion    //converge or diverge, to do this we check up to Z[499],    //and if its absolute value is not greater than 2 then we    //can safely assume that it converges    Z[1].a = 0;    Z[1].b = 0;    bool converge = true;    for(int c = 0; (c < 500)&&(converge); c++)    {      Z[0] = Z[1]*Z[1] + P;            if(Z[0].abs() > 2.0) // .abs() returns the absolute value      {        converge = false;      }      // recycling      Z[1] = Z[0];    }    if(converge)    {      //if it converge you might want to multiply the color      //value to fit a special color format, as it is often < 1.0      result[x][y].blue = Z[0].abs();      result[x][y].red = 0.0;      result[x][y].green = 0.0;     }    else    {      //if it deverges you usually get very high values (even      //though it exits the loop the first timemits higher than 2      //so i usually divide it by a constant (100 in this case)      result[x][y].blue = 0.0;      result[x][y].red = Z[0].abs(); * 0.01;      result[x][y].green = Z[0].abs(); * 0.01;    }       // now changing P so its ready for the next screen coordinate:    P.a += add;  }  P.b += add;  P.a = start_x;}// the next thing to do is to draw/save the color values in the// "result" array      


the definition of the complex class is somwhere here aswell



(There is no border around this image)


[edited by - Jesper T on April 28, 2002 3:28:48 PM]
I made a non-realtime Windows Mandelbrot Set Generator, the source and executable can be found here:
http://www.angelfire.com/games4/parsec/mandelbrot.zip
(You have to cut & paste this into your url address bar because Angelfire doesn''t allow direct-linking)
This should demonstrate the rendering process... be sure to read the readme for info on the settings and controls!!!
-Jesse
| The Hitchhiker''s Guide to Programming |"That is not dead which can eternal lie,And with strange aeons even death may die."-H.P. Lovecraft
basically realtime versions use less points and interpolate the results. there is no need to for a sperate thread because you can render a fractal image in less the 15ms if you really optimize the code and reduce the number of points tested. (the numebr of points tested is the most important part).

edit: also just as a test i decided to write a realtime julia set viewer. to my surprise it was quite easy. keeping the maxinterations down to 15 or so (and lowerer it depending on where you are in the mandalbrot set) means you get a great image with fast realtime results. dont worry if the low max iters seems too low, in fact its good unless you are in certain places in the mandalbrot set in which you may want to increase it. in fact you could set up a simple mapping system that changes the max interations done depending on where you are in the mandalbrot set to help keep the framerate high 9at certain places in the set the fractal is so simple that high interations dont yield a better picture).

ignore Jesper T's code (since its a bit wrong compared to the information i have seen on the net about the mandalbrot and juila sets). instead read the explaintion at http://www.students.tut.fi/~warp/Mandelbrot/ which explains the julia and mandalbrot set rather well (with some example code). its more of a tutorial in working with mandalbrot fractals and the julia set. please read the ENTIRE page and dont just copy the code. its very important that you go through step by step so you can understand the math and what is going on. this is crucial for you to optimize it for realtime viewing and figuring out good points to use to change the julia set into a flowing image rather then a jumpy crazy thing. remeber you dont need a high ammount of iterations to create a decent looking image, especially if you are not zoomed in, and are creating a realtime view.

have fun with it.

[edited by - a person on April 27, 2002 2:41:29 AM]
Whats wrong with it?
The explanation in your link is basically the same as both mine and the code Aphelions program. Dont post without knowing what you are talking about.

If you click my sig youll find out what ive created using basically that code.




(There is no border around this image)

[edited by - Jesper T on April 28, 2002 3:23:19 PM]
there is only one main thing wrong, is that its much faster to do the abs of Z manually and not take the square root. then compare to 4 instead of 2. remeber he was looking for fast realtime rendering of fractals, and the sqrt() is VERY slow. also i feel you failed to explain the importance of the max interations and then hardcodd it to such a high value. also, you did not mention that you can use the value of c when calculating the colors instead of using Z. while not much faster or slower, its something worth mentioning. i feel your code/expaination was only slightly misguided, because he is concerned with optimizations. now i understand that you need to comprehend something before optimizing, but by the same token things that can lead to optimization should be mentioned.

This topic is closed to new replies.

Advertisement