views:

546

answers:

7

Hi,

I've been pretty interested in coding a Mandelbrot Set zoom and have already done it twice. However there were problems with each one.

The first time I thought it'd be cool to do it in javascript... but that was so damn slow. Then I did it in C++, which worked great until you zoomed so far that the units on the graph got to the smallest point of C++'s double precision, so it just became pixelated.

So I'm looking for a language that'll be able to handle extremely precise floating point numbers and is also extremely fast at drawing graphics (which require huge loops for each pixel, each frame).

That is unless somebody can provide a solution to the C++ doubles?

Remember this is a zoom. So it doesn't just render static parts of the Mandelbrot Set, but keeps zooming in on parts.

Any suggestions?

Thanks a lot.

+1  A: 

I'd take a look at the source code for a public domain Madlebrot generator named WinFract. It uses very high precision integer arithmetic to do all the fractal calculations, is very fast as a result, and is very accurate.

Charles Bretana
A: 

C++ or C with MPFR.http://www.mpfr.org .

Jared Updike
Also, you can save a lot of time and just use a high performance, interactive fractal system like UltraFrac: basically Photoshop for fractals. It depends if your goal is to make a slick movie or to enjoy fiddling around with code and doing it yourself.
Jared Updike
Ahh...I wasn't seeing it before, but I think Google eventually figured it out for me (yay!). Are you talking about UltraFractal?
Beska
Sorry about that. Yes I meant UltraFractal. Stupid nicknames I make up for stuff...
Jared Updike
+1  A: 

I think you're likely to run into problems as soon as you go beyond double precision...I'm sure that there are libraries out there that handle extended precision for C++, but I'm guessing you take a huge hit in speed.

So why not use the best of both worlds...normal C++ double precision, until you start hitting the limits, and then jump to slower-but-more-precise library implemented arbitrary precision. Presumably this is what you would want to do within a library like this anyway...extend precision only as needed, so that you're not doing a lot of extra calculation that isn't required for the current zoom-level.

Beska
You can zoom quite deep before needing to switch between doubles and higher precision software. I forget the exact zoom level... Would be interested if anyone has a reference.
Jared Updike
+3  A: 

If you think that you need more precision, check out TTMath. A super fast bignum library. You specify the precision at compile-time through a template parameter and that's it!

#include "ttmath/ttmath.h"
#include <iostream>

int main()
{
   // bigdouble consists of 1024*4 bytes for the mantissa
   // and 256*4 bytes for the exponent.
   // This is because my machine is 32-bit!
    typedef ttmath::Big<1024, 256> bigdouble; // <Mantissa, Exponent>

    bigdouble x = 5.05544;
    bigdouble y = "54145454.15484854120248541841854158417";
    bigdouble z = x * y * 0.01;

    std::cout << z;

    return 0;
}


Also, you can use it with std::complex very easily:

// <Mantissa, Exponent>
typedef ttmath::Big<1024, 256> bigdouble; 
typedef std::complex<bigdouble> mycomplex;

mycomplex c("10.1111111111255747858778855",
      "6544444444853.484847778745848");
c = c * c * c + mycomplex(1.0, 5.0);
AraK
Cool library! Thanks for pointing that out.
Jared Updike
+1  A: 

I remember running into this same problem with a simple Mandelbrot generator I had developed in Turbo Pascal back in 1996 or so. I didn't even have a FPU in my system, so it was excruciatingly slow.

Anyway, back in the day, Fractint was the killer application for all things fractal. I remember doing a bit of research and coming across their solution to the precision and arbitrary depth zoom problem.

I don't know if it has aged well when compared to other open source solutions (that have clearer licenses), but seems relevant to your question.

As others have already pointed out, your choice of language probably isn't as important as the libraries available to you on that platform.

Joe Holloway
A: 

I know someone who implemented one using JavaScript and the canvas tag. He said that it's faster in Tracemonkey than in Squirrelfish, which came as a bit of surprise to me.

greyfade
A: 

I've written a mandelbrot image generator in C which uses the MPFR library for zooming far beyond long double. With MPFR, you can specify the precision at run time, which has it's benefits when calculating images embedded deep within the M-Set - you only need calculate to the precision needed.

mdz - Mandelbrot Deep Zoom http://www.jwm-art.net/mdz/

Depending on the complexity of the area you zoom into (and also how obsessed you are with the M-Set), the MPFR performance is still very usable. I'm running it on a 64bit 3ghz Intel Core II.

James Morris