2012-01-21 52 views
2

我已经走到这样的:着色Mandelbrot集

float MinRe = -2.0f; // real 
float MaxRe = 1.0f; 
float MinIm = -1.0f; // imaginary 
float MaxIm = MinIm + (MaxRe - MinRe) * WindowData.Height/WindowData.Width; 

float Re_factor = (MaxRe - MinRe)/(WindowData.Width - 1); 
float Im_factor = (MaxIm - MinIm)/(WindowData.Height - 1); 

int MaxIterations = 50; 
int iter=0; 

for (int y = 0; y < WindowData.Height; ++y) 
{ 
    double c_im = MaxIm - y * Im_factor; // complex imaginary 
    for (int x = 0; x < WindowData.Width; ++x) 
    { 
     double c_re = MinRe + x * Re_factor; // complex real 

     // calculate mandelbrot set 
     double Z_re = c_re, Z_im = c_im; // Set Z = c 
     bool isInside = true; 

     for (iter=0; iter < MaxIterations; ++iter) 
     { 
      double Z_re2 = Z_re * Z_re, Z_im2 = Z_im * Z_im; 
      if (Z_re2 + Z_im2 > 4) 
      { 
       isInside = false; 
       break; 
      } 
      Z_im = 2 * Z_re * Z_im + c_im; 
      Z_re = Z_re2 - Z_im2 + c_re; 
     } 

     if(isInside) 
     { 
      GL.Color3(0, 0, 0); 
      GL.Vertex2(x, y); 
     } 
    } 
} 

我曾在几个方面尝试过,但大部分的时间用单一颜色的周围设置,或整个屏幕搭配同色系的结束。

如何正确设置颜色?

+0

http://en.wikipedia.org/wiki/Mandelbrot_set#Computer_drawings – Mat

+0

您可能会发现一些有用的建议[here](http://stackoverflow.com/questions/369438/smooth-spectrum-for-mandelbrot-set-rendering) –

回答

1

当我想这一点,我只设置外部颜色RGB(值,值,1)其中,值(在你的说法)的(iter/MaxIterations)第四根。这是从白色到蓝色的相当好的淡出。虽然没有duffymo那么明亮,但是没有“条纹”效果。

0

我根据经验发现,如果使用类似的东西:色彩(R,G ,B)其中R,G,B取值为0到255之间的值。

然后这个函数给出了一个非常好看的结果。 f(x,f,p) = 255*(cos(sqrt(x)*f + p))^2其中x表示当前迭代,f的频率和p的相位。

,然后应用功能与120°的相位差,每种颜色的说法:

color(f(iter,1,0),f(iter,1,120),f(iter,1,240)