【问题标题】:Coloring mandelbrot set着色曼德布罗集
【发布时间】:2012-01-21 14:26:25
【问题描述】:

我想出了这样的事情:

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);
        }
    }
}

我尝试了几种方法,但大多数时候都以单色结束,或者整个屏幕具有相同的颜色。

如何正确设置颜色?

【问题讨论】:

标签: opengl mandelbrot


【解决方案1】:

当我尝试这个时,我只是将外部颜色设置为 RGB (value, value, 1),其中 value 是(用你的话来说)(iter / MaxIterations) 的第四个根。从白色到蓝色的渐变效果非常好。不过没有 duffymo 的那么亮,但没有“条纹”效果。

【讨论】:

    【解决方案2】:

    我是这样做的:查看 Source Forge 存储库以获取源代码。

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

    【讨论】:

      【解决方案3】:

      我凭经验发现,如果你使用类似的东西:color(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)

      【讨论】:

        【解决方案4】:

        尝试显示您的计算结果。检查您的着色功能需要什么输入

        另见

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

        HTH

        亚当

        【讨论】:

        • 欢迎您。我知道你还不允许离开 cmets,但这种类型的答案真的应该是一个。 :)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-10-26
        • 2017-12-03
        • 1970-01-01
        • 1970-01-01
        • 2013-12-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多