SFML community forums
General => SFML projects => Topic started 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
- Source: GitHub (https://github.com/eXpl0it3r/Fractal) (Some C++11 features are required!)
- Windows 32bit: Fractal-Win32.7zip (https://github.com/downloads/eXpl0it3r/Fractal/Fractal-Win32.7z) [838 KiB]
How to Use
- One can zoom-in with the mouse by selecting a rectangle on the window.
- The arrow keys [Up] and [Down] can be used to raise or lower the precision value shown in the top left.
- The [Return] key will force a rerendering of the fractal.
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?
- Code cleanup. At the moment the code is still quite messy and needs some refactoring.
- Nicer default colors settings. The current settings don't create the nicest compositions.
- Interactive and user-defined color settings. The user should be able to change the colors the way he wants.
- Optimization and trying to get a deeper zooming level.
-
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.
-
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...
-
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.
-
Nicely done, also compiles without problems on Debian GNU/Linux with G++ 4.7.
-
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).
-
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. ;)
-
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.
-
If you go deep enough you can see god. :)
You say this is pure mathematics?
-
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).
-
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