Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Julia Fractals

Author
Message
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 21st Jan 2007 08:23 Edited at: 26th Jan 2007 10:04
Hey everyone,

This year, we have to discuss a self-chosen topic for math. And the topic me and my friend picked are fractals.

I started out with the julia fractals:
y = x^2 + c with c being input

For some cool effects: (Re stands for Real part of, Im for Imaginary part of --> c can be complex)

Not really a cool effect. It gives a circle
Re(c) = 0.0
Im(c) = 0.0


This one starting to be it:
Re(c) = -0.5
Im(c) = 0.0


Re(c) = -1.0
Im(c) = 0.0

What about this!!
Re(c) = -0.5
Im(c) = -0.55


This one looks like a double dragon...
Re(c) = 0.325
Re(c) = 0.417


And finally a nice lightning effect (thx Code Dragon)
Re(c) = 0.4
Im(c) = 0.6


or
Re(c) = 0.0
Im(c) = 1.0


And the code: Press enter to return to the real and imaginary input.



For the people interested in how it works:
This is the algorithm

1) I used a vector to calculate with the imaginary numbers. The x vector is the real axis, the y vector is the imaginary axis.
For kwadrating an imaginary number, you have to kwadrate the length of the vector and double the angle it forms with the real axis. To add the real and imaginary c, I simply add Re(c) to the x vector and Im(c) to the y vector.

2) I repeat the proces with the vector until the value is bigger than a set length, or the number of maximum iterations was passed.

3) If the value still didn't pass the maximum value, then it means there is an attractor(?) (aantrekker in dutch), and the pixel should be black.
Else, the number of iterations the value needed to get over the maximum value is used for the color.

[edit] For real time rendering:



[edit] The last versions:
Julia (blue):


Mandlebrot (blue):


Line iteration:


It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 21st Jan 2007 20:45
Cool, I don't really understand the algorithm, but to make complex fractals in a small amount of code is amazing. Is there any way to zoom in or increase the resoultion?

This makes a cool lightning pattern.

Re(c) = 0.4
Im(c) = 0.6

Quote: "Gimme teh code!"

Thank you for not flooding the forums with posts like this.
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 22nd Jan 2007 23:44
Wow that is quite cool. I'll have to learn how it works.

It might also make a nice screen saver - Change the complex number slowly over time while rendering the fractal. I guess it would need to be really slow or low resolution, but could still be interesting to watch.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Jan 2007 00:31 Edited at: 23rd Jan 2007 00:32
I remember it was I think spooky who made a Mandelbrot fractal that you could zoom in to. I think one day, when processing power gets really high, people will be able to make one where you can zoom in flalessly, just like moving through it. Imagine that, travelling through a fractal! If anyone here has the guts to try, I'd love to see it

Really cool code there Sven. Keep it up

sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 23rd Jan 2007 04:33
wow possibly neatest thing ive seen in quite a while

If at first you dont succeed, LOWER YOUR STANDARDS.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 24th Jan 2007 14:16 Edited at: 24th Jan 2007 14:21
Thx for the feedback.

Quote: "Is there any way to zoom in or increase the resoultion?"


Yes there is.

In this piece of code:

You can change the resolutions by changing



And you can change the zoomfactor with

which also depends of the size of the rendered image.

the parameters (just before the main loop)
CreateImage(1, 1.0 / Zoom#, -1.0, -1.0)
determine the offset (1u to the right and top - not bottom)


Fractals actually need very intensive calculation (it generates a value and generates another value with the previous one X32(max)) for every pixel on the screen. That is why it is so slow.

Quote: "I remember it was I think spooky who made a Mandelbrot fractal that you could zoom in to"

The mandelbrot fractal also uses the function f(x) = x^2 + C, but C is the variable here and the start value for x is always 0.
Julia fractals use the x as the variable.

Quote: "
It might also make a nice screen saver - Change the complex number slowly over time while rendering the fractal. I guess it would need to be really slow or low resolution, but could still be interesting to watch."


I think it is a little too slow for a screen saver.
What you could do for a screen saver though, is render it with random real and imaginary numbers after a set amount of time...

[edit] For anyone interested, I added a code to the first post where the fractal is rendered real time instead of the boring percents...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th Jan 2007 19:39 Edited at: 25th Jan 2007 19:40
Here I am with a new fractal program:


Before running it, you need to copy paste, or write your own code in the part





The syntax of the command is this:


To change the number of iterations, change the line just after the code part. Meaning this line:




And here are some examples. Paste this code in the part described above!!!

A small example of... A spiral you might call it?


Or a tree:


I saw this one in a book once, but I can't remember the name:


A final word of advice
It is best not to overdo it in the number of iterations. 15 is do-able with one AddStandardLine, but I would advice 10 for 2 and 5 for more.
I have experienced some crashes (or maybe it was just working kinda long) when I used 30 for the number of iterations.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 26th Jan 2007 08:50 Edited at: 26th Jan 2007 10:05
Here's the mandlebrot fractal with making about 10 lines different from the julia fractals:



And at this point, I'm going to try to improve the speed of the fractal generation process.

[edit]

I improved the algorithm big time. It can draw a mandlebrot (800x600) in 15s on my machine.
It does most of the julia fractal between 10s en 20s for 600x600 images.

I also added some color (blue, ofcourse)

Julia fractals:


And the mandlebrot fractal:




I will post some pics in the meantime... [edit] done

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
UnderLord
21
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 26th Jan 2007 14:47
Thats pretty awsome

"I have noticed even people who claim everything is predestined, and that we can do nothing to change it, look before they cross the road."
El Goorf
18
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 26th Jan 2007 18:03 Edited at: 26th Jan 2007 18:04
wow i've been wishing for ages that part of my naths course world involve a self study course, in which case i would have done fractals too

now im jealous >.>
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 26th Jan 2007 19:14
Maybe do self-study on your own?

I self-study alot. For example: I just finished differentials even though we only get a small part at the end of high-school (which we haven't even started yet)...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 26th Jan 2007 21:19
Awesome fractals. I'm going to make a program that draws the dragon fractal soon, quite an interesting shape. I'll post here when it's done.

Keyboard not found. Press F1 to continue.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 26th Jan 2007 21:45 Edited at: 26th Jan 2007 21:46
Sure, go ahead

I found a page with some fractals and for each its c and equation.
Here

But beware, some of them are zoomed mandlebrot fractals, or are other functions than f(x) = x^2 + c (the julia fractals).

Some nice pics I found are:
c = -1.0 + 0.3i
c = 0.285 + 0.013i

And now, I'm planning on expanding the fractal generator with other functions than f(x) = x^2 + c...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 27th Jan 2007 14:18
Here's the dragon fractal maker. Each iteration takes twice as long as the last, so you won't be able to get much farther than the 16th iteration.

This looks best when it's at your monitor's maximum resolution.



Keyboard not found. Press F1 to continue.
Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 31st Jan 2007 02:21
WAY cool man, 2 thumbs up! I have been looking for more fractal and math work done in DBP, thanks! This will help me out a great deal with my current project.

Quit planning to make a game and make a game.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 31st Jan 2007 13:07
This project is meant to create a pretty complete fractal program in the end...

Something I noticed in my current work:
When using higher powers for the function f(x)=x^n + c, here's what happens:

F(x) = x^3 + (-0.5 + 0.55i)


F(x) = x^4 + (0.5 + 0.5i)


It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 31st Jan 2007 21:46 Edited at: 31st Jan 2007 21:53
I had some fun looking at the results when tinkering around with this. I decided to have it automatically generate the images for me using this code:



It is a slightly modified version of the julia blue that was on here. It has made about 700 images so far with some REALLY interesting results. I grabbed a few hundred and stuffed them into windows movie maker to watch a 'video' of the results, and that too was kind of interesting. Check out the screenie of the results>>>


Edit:
BTW, -1,-.3 is way cool

Quit planning to make a game and make a game.

Attachments

Login to view attachments
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 1st Feb 2007 00:38
Noticed that because of the JPEG compression, the cooler fractals tend to have higher file sizes.
Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 1st Feb 2007 01:39 Edited at: 1st Feb 2007 01:40
Here is a short 14 second video of some automated fractal captures:

http://www.youtube.com/watch?v=PxzVGjjLWdI

Quit planning to make a game and make a game.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Feb 2007 19:39
That's alot of julia fractals

I watched your video and it's a pretty cool effect I have to say...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Brain111
17
Years of Service
User Offline
Joined: 5th Feb 2007
Location: In my own little world.
Posted: 7th Feb 2007 03:28
That was cool. I have no idea what any of the math does. For some reason when i type in letters for the values, it draws these neat little circles.
DDFDS
17
Years of Service
User Offline
Joined: 20th May 2007
Location:
Posted: 20th May 2007 21:26
Heres a mandelbrot generator with a zoom function.
After it has drawn the picture use the mouse wheel to change the size of the area you want to zoom into then press it.
S saves the picture
R resets back to start
and spacebar quits

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-23 00:34:05
Your offset time is: 2024-11-23 00:34:05