找的一点代码

  1. inline double mandelbrot7(double* xList,double* yList,const long max_iter){   
  2.     const static double M=256;   
  3.     const static double lnln_M=loglog(M);   
  4.     const double& x0=xList[0];   
  5.     const double& y0=yList[0];   
  6.     double x_bck=0;   
  7.     double y_bck=0;   
  8.     double x=x0;   
  9.     double y=y0;   
  10.     long i=0;   
  11.     for (;i<max_iter;++i){   
  12.         if (x*x+y*y>=M)   
  13.             break;   
  14.         x_bck=x;   
  15.         y_bck=y;   
  16.         double tmp=x*x-y*y+x0;   
  17.         y=x*y*2+y0;   
  18.         x=tmp;   
  19.         xList[i+1]=x;   
  20.         yList[i+1]=y;   
  21.     }   
  22.     if (i!=max_iter){   
  23.         const double lnln_Z=loglog(x*x+y*y);   
  24.         const double lnln_Zbak=loglog(x_bck*x_bck+y_bck*y_bck);   
  25.         return i-2-(lnln_Z-lnln_M)/(lnln_Z-lnln_Zbak);   
  26.     }else  
  27.         return i;   
  28. }   
  29. inline Color32 coloring7(const double iter,const long max_iter,double* xList,double* yList,const Colorf& errorColorIn,Colorf& errorColorOut,double k=1){   
  30.     Colorf color=errorColorIn;   
  31.     if (iter==max_iter){   
  32.         const double x=xList[max_iter];   
  33.         const double y=yList[max_iter];   
  34.         double z=sqrt(x*x+y*y);   
  35.         double zd=z-sqrt(xList[max_iter-1]*xList[max_iter-1]+yList[max_iter-1]*yList[max_iter-1]);   
  36.         color.addColor(Colorf(sinColorf(z*2000*k),sinColorf(y*x*1000*k),sinColorf(zd*1000*k)));   
  37.     }else{    
  38.         color.addColor(Colorf(sinColorf(iter*20*k),sinColorf(iter*15*k+85),sinColorf(iter*30*k+171)));   
  39.     }   
  40.     Color32 resultColor=color.toColor32();   
  41.     errorColorOut=color;   
  42.     errorColorOut.subColor(resultColor);   
  43.     return resultColor;   
  44. }   
  45. void draw_mandelbrot7(const TPixels32Ref& dst,const TViewRect& rect,const long max_iter){   
  46.     std::vector<double> xList;   
  47.     std::vector<double> yList;   
  48.     xList.resize(max_iter+1);   
  49.     yList.resize(max_iter+1);   
  50.     for (long y=0;y<dst.height;++y){   
  51.         Colorf errorColor(0,0,0);   
  52.         for (long x=0;x<dst.width;++x) {   
  53.             double x0=(2*rect.r)*x/dst.width+rect.x0-rect.r;   
  54.             double yr=rect.r*dst.height/dst.width;   
  55.             double y0=(2*yr)*y/dst.height+rect.y0-yr;   
  56.             xList[0]=x0;   
  57.             yList[0]=y0;   
  58.             double iter=mandelbrot7(&xList[0],&yList[0],max_iter);   
  59.             dst.pixels(x,y)=coloring7(iter,max_iter,&xList[0],&yList[0],errorColor,errorColor);   
  60.         }   
  61.     }   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值