Mandelbrot set in C++




This is my first Mandelbrot set in C++. (:-))

Look at this function. I think that it can not be coded simpler.
It is good for explaining but execution time is very long.

// it computes integer escape time iteration for mandelbrot set f(z)= z*z +c
// based on the code by komorra from program fractaldream
// http://komorra.110mb.com/fractaldream/source.txt
// http://binboy.sphere.pl/index.php?show=207


int iterate_mandel(complex C , int imax, int bailout)
{
int i;
std::complex Z(0,0); // initial value for iteration Z0
for(i=0;i<=imax-1;i++)
{
Z=Z*Z+C; // overloading of operators
if(abs(Z)>bailout)break;
}
return i;
}

This is faster version without use of complex type for z variable.

int EscapeTime(std::complex C , int iter_max, int bailout2)
{
// z= x+ y*i
long double x ,y ;
//
long double u, v;
int iter; // number of iteration
//z0=0+0*i
//z1=c
y =C.imag();
x =C.real();
iter=1; //there was 1 iteration
u = x*x ;
v = y*y;
if ( u + v > bailout2 ) return iter; // point is in target set =no need to iterate
//
do // iteration loop
{
// Fc(z)= z*z +c
y = 2 * x * y + C.imag();
x = u - v + C.real();
u = x*x;
v = y*y;
iter+=1;
} while (( u + v <= bailout2 ) && iter < iter_max );

return iter;
}


Diffrent algorithms :
IDE = Dev-C++ v 4.9.9.2
OS - Windows
type - console program
graphic library : winBGIm .
Most important parts of this programs are based on code of program mandel by Wolf Jung.
Thx for publishing the code under GNU General Public License

diffrences in drawing code ( for 16 colors from 0 to 15 ) :

int last_iter= escape_time(C,iter_max,bailout2);

boolean escape time :
if (last_iter==iter_max) { putpixel(ix,iy,BLACK);} // interior
else putpixel(ix,iy,GREEN); // exterior

eLSM/M :
if (last_iter==iter_max) { putpixel(ix,iy,BLACK);} // interior
else putpixel(ix,iy,last_iter % 15); // exterior

pseudo continus escape time :
if (last_iter==iter_max) { putpixel(ix,iy,BLACK);} // interior
else putpixel(ix,iy,(50+last_iter) % 255); // exterior
( here are 16 colors from 0 to 15. Above 15 is red gradient from 16 to 16+255 )

arg(phi(c)) = external angle ( argument)
if (last_iter==iter_max) { putpixel(ix,iy,BLACK);} // interior of Mset
else putpixel(ix,iy,mturn(C)); // exterior of M-set

log(phi(c)) = CPM/M :
if (last_iter==iter_max) { putpixel(ix,iy,BLACK);} // interior of Mset
else putpixel(ix,iy,mlogphi(C)); // exterior of M-set = log(Phi)

period of hyperbolic component:
int last_iter= mandelperiodtime(C,iter_max,bailout2); // iter+iter_max
// drawing code */
if (last_iter>iter_max) { putpixel(ix,iy,(last_iter-iter_max) % 15);} // interior
else putpixel(ix,iy,last_iter); // exterior

binary decomposition of exterior of M-set:
int last_iter= mbinary(C,iter_max,bailout2);
// drawing code */
if (last_iter==iter_max) { putpixel(ix,iy,BLACK);} // interior
else putpixel(ix,iy,last_iter % 15); // exterior

DEM/M = mandel_dist :
// compute escape time
int last_iter= escape_time(C,iter_max,bailout2);
// drawing code */
if (last_iter==iter_max) { putpixel(ix,iy,BLACK);} // interior
else putpixel(ix,iy,mdist(C,iter_max,step_x)); // exterior and boundary

bof60 and bof 61:
int last_iter= mclosetime(C,iter_max,bailout2);
// drawing code */
if (last_iter>=iter_max) { putpixel(ix,iy,last_iter - iter_max);} // interior
else putpixel(ix,iy,WHITE); // exterior


Main page


Autor: Adam Majewski adammaj1-at-o2-dot-pl
Feel free to e-mail me. (:-))

Made with: EditPlus www.editplus.com



About

republika.pl/fraktal