inline double mandelbrot7(
double* xList,
double* yList,
const long max_iter){
const static double M=256;
const static double lnln_M=loglog(M);
const double& x0=xList[0];
const double& y0=yList[0];
double x_bck=0;
double y_bck=0;
double x=x0;
double y=y0;
long i=0;
for (;i<max_iter;++i){
if (x*x+y*y>=M)
break; x_bck=x; y_bck=y;
double tmp=x*x-y*y+x0; y=x*y*2+y0; x=tmp; xList[i+1]=x; yList[i+1]=y; }
if (i!=max_iter){
const double lnln_Z=loglog(x*x+y*y);
const double lnln_Zbak=loglog(x_bck*x_bck+y_bck*y_bck);
return i-2-(lnln_Z-lnln_M)/(lnln_Z-lnln_Zbak); }
else return i; }
inline Color32 coloring7(
const double iter,
const long max_iter,
double* xList,
double* yList,
const Colorf& errorColorIn,Colorf& errorColorOut,
double k=1){ Colorf color=errorColorIn;
if (iter==max_iter){
const double x=xList[max_iter];
const double y=yList[max_iter];
double z=sqrt(x*x+y*y);
double zd=z-sqrt(xList[max_iter-1]*xList[max_iter-1]+yList[max_iter-1]*yList[max_iter-1]); color.addColor(Colorf(sinColorf(z*2000*k),sinColorf(y*x*1000*k),sinColorf(zd*1000*k))); }
else{ color.addColor(Colorf(sinColorf(iter*20*k),sinColorf(iter*15*k+85),sinColorf(iter*30*k+171))); } Color32 resultColor=color.toColor32(); errorColorOut=color; errorColorOut.subColor(resultColor);
return resultColor; }
void draw_mandelbrot7(
const TPixels32Ref& dst,
const TViewRect& rect,
const long max_iter){ std::vector<
double> xList; std::vector<
double> yList; xList.resize(max_iter+1); yList.resize(max_iter+1);
for (
long y=0;y<dst.height;++y){ Colorf errorColor(0,0,0);
for (
long x=0;x<dst.width;++x) {
double x0=(2*rect.r)*x/dst.width+rect.x0-rect.r;
double yr=rect.r*dst.height/dst.width;
double y0=(2*yr)*y/dst.height+rect.y0-yr; xList[0]=x0; yList[0]=y0;
double iter=mandelbrot7(&xList[0],&yList[0],max_iter); dst.pixels(x,y)=coloring7(iter,max_iter,&xList[0],&yList[0],errorColor,errorColor); } } }