Skip to main content
GameDev.net gamedev.net
🔒 Locked

Fractal Image Algorithm

Started by Glass_Knife Aug 6, 2010 at 10:38 AM 3 replies 2.5k views
Original Post
Glass_Knife
Glass_Knife
Long story short - A friend of mine at work belongs to a Fractal Society. I wanted to create and image of the Mandelbrot set. I've googled, but I can't find a simple code example. I see lots of math, and I understand how to create it (I think) but how is it turned into a visual example.

My coworker said something about a test for infinity, and keeping a count of every time a value is visited, but I still can't code up a program that makes an image.

Anyone with some guidance, I would appreciate it.

Thanks,
KulSeran
KulSeran
From Wiki.
You are looking at the formula F(Z) : Z -> Z2 + C. The objective is, for all pixels in your image, use the X,Y coordiate as a complex number C=X+Yi and test for several iterations with Z starting at 0, if Z = F(Z); escapes beyond 2. If it doesn't escape, it is the black center of the shape. If it does escape, use the number of iterations it took to escape to choose a color based on that speed of escape (or just make it white).

The complex math for F(Z) is fairly simple. You treat Z as x and y, and C as your X,Y coordintate, and F(x,y) becomes:
xi+1 = xi2 - yi2 + X
yi+1 = 2*xi*yi + Y
if ( xi2 + yi2 > 4 ) you escaped the disk, and should stop iterating this point. If after N iterations this never happens, then you are in the fractal.

--I miss Albuquerque. LA doesn't have good green chile.
Glass_Knife
Glass_Knife
Quote:
Original post by KulSeran
--I miss Albuquerque. LA doesn't have good green chile.


I don't know what I'm going to do when I leave. The chile is soooo good.

Thanks for the info. I need to read it about 20 more times and code it up. I'm sure I'll have more questions after that...

Thanks Again,

CryoVenom
CryoVenom
I made a mandelbrot renderer, but I noticed that when I zoom in really far it becomes blocky. Is this normal for a basic mandelbrot renderer and is there a way to cause it to be "infinite"? Or is there specifically something I am doing wrong?

I can show the part where I calculate the value of the formula if someone requests to see it.
Moomin
Moomin
Quote:
Original post by CryoVenom
I made a mandelbrot renderer, but I noticed that when I zoom in really far it becomes blocky. Is this normal for a basic mandelbrot renderer and is there a way to cause it to be "infinite"? Or is there specifically something I am doing wrong?

I can show the part where I calculate the value of the formula if someone requests to see it.


Something is wrong, it is likely a precision issue. A quick way to tell if it is a precision issue would be to change from float to double, and record if the zoom level at which the 'blockiness' starts is increased.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.