我想出了一些类似的东西:
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);
}
}
}我尝试了几种方法,但大多数时候都是以单一颜色结束,或者整个屏幕都是相同的颜色。
如何正确设置颜色?
发布于 2012-01-22 01:21:37
当我尝试这样做时,我只是将外部颜色设置为RGB ( value,value,1),其中value是(用您的说法) (iter / MaxIterations)的第四个根。这是一个相当漂亮的从白色到蓝色的渐变。虽然没有duffymo的那么亮,但没有那么“条纹”的效果。
发布于 2012-01-21 22:27:51
下面是我是如何做到这一点的:查看Source Forge存储库的源代码。
http://craicpropagation.blogspot.com/2011/03/mandelbrot-set.html
发布于 2017-05-21 09:15:24
我根据经验发现,如果你使用这样的东西: 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)
https://stackoverflow.com/questions/8953715
复制相似问题