2012-01-21 51 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)