着色mandelbrot集

时间:2012-01-21 14:26:26

标签: opengl 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);
        }
    }
}

我尝试过几种方式,但大部分时间以套装的单色或全屏相同的颜色结束。

如何正确设置颜色?

4 个答案:

答案 0 :(得分:1)

以下是我的工作方式:查看Source Forge存储库中的源代码。

http://craicpropagation.blogspot.com/2011/03/mandelbrot-set.html

答案 1 :(得分:1)

当我尝试这个时,我只是将外部颜色设置为RGB(值,值,1),其中值(在您的说法中)是(iter / MaxIterations)的第四个根。这是从白色到蓝色的非常好的淡化。然而,并不像duffymo那么明亮,但是没有那么“条纹”效果。

答案 2 :(得分: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)

答案 3 :(得分:-1)

尝试显示计算结果。检查着色功能需要哪些输入

另见

http://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/Mandelbrot_set

HTH

亚当