Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Fractal - Mandelbrot Set  (Read 9343 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Fractal - Mandelbrot Set
« 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 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



Download

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.
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.
« Last Edit: April 08, 2014, 12:09:31 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: Fractal - Mandelbrot Set
« Reply #1 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:


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.
« Last Edit: November 14, 2012, 12:48:29 am by Perde »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Fractal - Mandelbrot Set
« Reply #2 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...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: Fractal - Mandelbrot Set
« Reply #3 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.
« Last Edit: November 14, 2012, 01:52:32 am by Perde »

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Fractal - Mandelbrot Set
« Reply #4 on: November 14, 2012, 09:08:56 am »
Nicely done, also compiles without problems on Debian GNU/Linux with G++ 4.7.

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Fractal - Mandelbrot Set
« Reply #5 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).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: Re: Fractal - Mandelbrot Set
« Reply #6 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: Fractal - Mandelbrot Set
« Reply #7 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.

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: Fractal - Mandelbrot Set
« Reply #8 on: November 15, 2012, 05:06:04 am »
If you go deep enough you can see god.  :)

You say this is pure mathematics?



masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Fractal - Mandelbrot Set
« Reply #9 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 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).
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: Re: Fractal - Mandelbrot Set
« Reply #10 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
« Last Edit: November 07, 2014, 02:39:50 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything