SFML community forums

General => SFML projects => Topic started by: eXpl0it3r on November 13, 2012, 10:43:57 pm

Title: Fractal - Mandelbrot Set
Post by: eXpl0it3r on November 13, 2012, 10:43:57 pm
Fractal - Mandelbrot Set

The past two days I've been working on a small application that draws the famous Mandelbrot set (https://en.wikipedia.org/wiki/Mandelbrot_set) and lets you zoom in quite a bit.
I hope you like it and I'm always open for questions, discussions, requests, suggestions, etc. :)

Impressions

(https://legacy.sfmluploads.org/cache/pics/282_frac4.png) (https://legacy.sfmluploads.org/cache/pics/280_frac2.png) (https://legacy.sfmluploads.org/cache/pics/279_frac1.png)

Download

How to Use

Technical Details
For those interested in how I do things in the background, I'll say a few words here and if you're really interested checkout the source (https://github.com/eXpl0it3r/Fractal).
I use two classes; the first one is a simple Application class, which creates a window, handles the input, drawing and managing of the resources and objects. The second one is the Fractal itself. It's derived from sf::Drawable and thus can be directly drawn onto the window. Within the class I'm using a sf::Sprite to render the generated texture. Since the fractal is actually a mathematical concept from which we define a way to convert the numbers into pixel information, I have to set every pixel by hand. For this procedure I'm using a std::vector of sf::Uint8 and call update() on the texture by directly accessing the underlying array of vector (C++11 feature vec.data()).
The part that consumes most of the time is the calculation and to speed things up I simply split up the screen into rectangles and run the calculations ins separate threads. Unfortunately the speedup isn't as good as one would want it to be, so I'll have to investigate further.
For further questions, just ask.

What's next?
Title: Re: Fractal - Mandelbrot Set
Post by: Perde on November 14, 2012, 12:31:05 am
Oh how I love those!
Sadly, it doesn't quite work, at least not for me.

I figured a video would be the easiest way to show what happens:
http://www.youtube.com/watch?v=5K9xY4V14fs

I was only using my mouse in the video, but pressing return has the same effect as when I'm trying to zoom. Up and Down do nothing else (visible) than change the value in the top left corner.
Also the OS is Windows 7 x64 if that's of any use.
Title: Re: Fractal - Mandelbrot Set
Post by: eXpl0it3r on November 14, 2012, 01:21:33 am
Hmmm... that's odd... :-\
Really strange that once it suddenly shows...

What also is strange that the font for the 'Please Wait!' doesn't work. Is this the Win32 I provided and do you have the DejaVuSans.ttf font next to the executable?
Is your graphics card driver uptodate and what graphics card do you have?
Other than that I can't really explain to myself what's going wrong there. I might be a precision problem of long double...
Title: Re: Fractal - Mandelbrot Set
Post by: Perde on November 14, 2012, 01:42:40 am
Yes, it's the .exe you provided with everything extracted as is from the archive.
Drivers are up to date for my Mobility Radeon HD 5650.

Odd indeed.

[edit]
To be a bit more specific about that "flash" at the end. I didn't see any of those during runtime, but the raw video showed one of them after each zoom (recorded with Fraps, IIRC with 60fps). I suppose it's Youtubes fault, that you only see it once.
Title: Re: Fractal - Mandelbrot Set
Post by: Tank on November 14, 2012, 09:08:56 am
Nicely done, also compiles without problems on Debian GNU/Linux with G++ 4.7.
Title: Re: Fractal - Mandelbrot Set
Post by: didii on November 14, 2012, 09:41:51 am
Very nice. Made it once with Matlab and that was a whole lot slower (could take up to several hours to build the first image).
Title: AW: Re: Fractal - Mandelbrot Set
Post by: eXpl0it3r on November 14, 2012, 10:49:15 am
Nicely done, also compiles without problems on Debian GNU/Linux with G++ 4.7.
Nice to hear that portable code is indeed portable. (Although I've also used GCC 4.7.x.) ;)

Very nice. Made it once with Matlab and that was a whole lot slower (could take up to several hours to build the first image).
Yeah MATLab is nice and quite fast for matrix stuff, but it will never reach the speed you can get from native application. ;)
Title: Re: Fractal - Mandelbrot Set
Post by: Perde on November 14, 2012, 08:21:52 pm
Well, I guess it's safe to say that there's something wrong with my computer. I wonder, since I just recently freshly installed the OS, what the hell it could be.
Title: Re: Fractal - Mandelbrot Set
Post by: kaB00M on November 15, 2012, 05:06:04 am
If you go deep enough you can see god.  :)

You say this is pure mathematics?
Title: Re: Fractal - Mandelbrot Set
Post by: masskiller on November 15, 2012, 06:19:35 am
Fractals are calculated using a recursive math function, the mandelbrot set is just a famous fractal out of the many existing. So yes, it's all pure math in concept.

Check https://en.wikipedia.org/wiki/Fractal (https://en.wikipedia.org/wiki/Fractal) for a nice read, they are quite interesting to see. You can implement them with an iterative algorithm as well, but the recursive function is the most famous (as it is how it's mathematically defined).
Title: AW: Re: Fractal - Mandelbrot Set
Post by: eXpl0it3r on November 15, 2012, 09:53:44 am
You say this is pure mathematics?
Yes, unless you want to go all philosophical, then you could ask yourself where the math comes from and how it can be so complex and yet still beautiful... :D