Opengl 着色mandelbrot集

Opengl 着色mandelbrot集,opengl,mandelbrot,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 =

我想到了这样的事情:

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);
        }
    }
}
float MinRe=-2.0f;//真实的
浮点最大值=1.0f;
浮点最小值=-1.0f;//虚构的
浮点最大值=最小值+(最大值-最小值)*WindowData.Height/WindowData.Width;
float Re_factor=(MaxRe-MinRe)/(WindowData.Width-1);
浮点Im_因子=(最大-最小)/(WindowData.Height-1);
int最大迭代次数=50;
int-iter=0;
对于(int y=0;y4)
{
isInside=假;
打破
}
Z_im=2*Z_re*Z_im+c_im;
Z_re=Z_re2-Z_im2+c_re;
}
如果(isInside)
{
GL.Color3(0,0,0);
GL.顶点2(x,y);
}
}
}
我试过几种方法,但大多数情况下都是以单色或全屏同色结束


如何正确设置颜色?

我是这样做的:查看SourceForge存储库中的源代码


当我尝试此操作时,我只是将外部颜色设置为RGB(value,value,1),其中value(用你的说法)是
(iter/MaxIterations)
的第四个根。从白色到蓝色的渐变效果非常好。虽然不如达菲莫的那样明亮,但“条纹”效果要少一些。

试着显示你的计算结果。检查着色功能所需的输入

另见


亚当

我根据经验发现,如果你使用这样的东西:颜色(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,1120),f(iter,1240)

您可能会发现一些有用的建议,欢迎您提出。我知道您现在还不允许留下评论,但这种类型的答案确实应该是一个。:)