着色曼德尔布罗集
我想到了这样的事情:
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);
}
}
}
我尝试了几种方法,但大多数时候都以周围的单色或整个屏幕的相同颜色结束。
如何正确设置颜色?
I have came up to something like this:
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);
}
}
}
I have tried in few ways, but most of the times ended with single color around set, or whole screen with the same color.
How to set up colors properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当我尝试这个时,我只是将外部颜色设置为 RGB (value, value, 1),其中 value 是(用你的话说)
(iter / MaxIterations)
的第四个根。结果是从白色到蓝色的渐变非常漂亮。虽然不如达菲莫那么明亮,但“条纹”效果较少。When I tried this, I just set the outside colour to RGB (value, value, 1) where value is (in your parlance) the fourth root of
(iter / MaxIterations)
. That comes out as a quite nice fade from white to blue. Not so bright as duffymo's, though, but with less of a 'stripy' effect.我是这样做的:查看 Source Forge 存储库中的源代码。
http://craicpropagation.blogspot.com/2011/03/mandelbrot-set.html
Here's how I did it: check out the Source Forge repository for source code.
http://craicpropagation.blogspot.com/2011/03/mandelbrot-set.html
我根据经验发现,如果你使用类似的东西: 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)
I found empirically that if you use something like that: color(R,G,B) where R,G,B takes values from 0 to 255.
Then this function gives a really good looking result.
f(x,f,p) = 255*(cos(sqrt(x)*f + p))^2
wherex
denotes the current iteration,f
the frequency andp
the phase.And then apply the function for each color argument with a phase difference of 120:
color(f(iter,1,0),f(iter,1,120),f(iter,1,240)
尝试显示您的计算结果。检查着色函数需要什么输入
另请参阅
http://en.wikibooks.org/ wiki/分形/Iterations_in_the_complex_plane/Mandelbrot_set
HTH
Adam
try to display result of your computation. Check what input is required by your coloring function
See also
http://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/Mandelbrot_set
HTH
Adam