/** # A visualization of the Mandelbrotset using adaptive grids. For a given complex number $\mathcal{c}$ one can define the sequence of numbers $z_{n}$ indexed with n as, $$z_{n+1}=z_n^2+\mathcal{c},$$ starting from $z_0=\mathcal{c}$. It can be shown that the sequence diverges in an absolute sense if $z_nz_n^* > 2$. The mandelbrot set can be visualized using color coding for the amount of iterations it takes to get $z_n$ such that $z_nz_n^* \geq 2$. Furthermore, there are sequenses that do not diverge (eg. the sequence corresponding to $c=-1$). Therefore we choose to stop checking for divergence after $n_{max}=2000$ iterations. A quadtree grid will be used, for the output we use standard functions supplemented with a costum color map named *doublerainbow*, after it's colorful palette. */ #include "grid/quadtree.h" #include "utils.h" #include "view.h" void doublerainbow (double cmap[NCMAP][3]){ for (int i = 0; i < NCMAP; i++){ cmap[i][0]=sq(sin((double)i*M_PI/64.)); cmap[i][1]=sq(sin(((double)i+20.)*M_PI/64.)); cmap[i][2]=sq(sin(((double)i+40.)*M_PI/64.)); }//Black saturation cmap[NCMAP-1][0]=0; cmap[NCMAP-1][1]=0; cmap[NCMAP-1][2]=0; } /** We zoom in on a pre-specified location. Here *xy* and *yz* are the real and imaginary part of the complex number that specifies the zoom-in location, respectively. */ double xz=-0.7447450302052016; double yz=0.1216630821053122; /** The visualization uses 2 scalar fields and a intermediate/dummy field. The number of iterations untill convergence are stored in the *cc* scalar field. However, for visualization purposes we visualize the logarithm of that number. So the color-coded field that has a linear mapping to the color bar is stored in *c*. Furtheremore, for maximum visual statisfaction, we mask the cells that do not divergece within *jmax* iterations, their locations are stored in the *m* field. */ scalar c[],cc[],m[]; double jmax=2000.; /** A grid resolution is set that corresponds to the resolution of the movie. */ int maxlevel = 9; double mm,avg,it,f,ag; int i; /** The zoom-in corresponds to a $2^{1040/40} = 67108864$ times magnificaton. */ int end = 520; double perit = 40; /** We define a function that calculates how many iterations it takes before the aforementioned sequence diverges. If it does not diverge within *jmax* iterations, it will return *jmax*. Also we track the total number of iterations made for each snapshot and store the result in *ag*. */ double determine_iterations(double x,double y){ double j=0.; double xx=xz+(x/f); double yy=yz+(y/f); double a=xx; double b=yy; double c; double ab=(sq(a)+sq(b)); while (j