Delphi 上 Mandelbrot 集的平滑着色算法
我在使用平滑着色算法时遇到问题。我只是没有在我的代码中实现它们。 这是在计算一些像素行后导致错误的主要代码:
g:=StrToInt(Edit3.Text); //maximum iteration count
for x:=0 to Width do
begin
for y:=0 to Height do
begin
zr:=x*(br-ar)/Width+ar;
zi:=y*(bi-ai)/Height+ai;
n:=1;
zr0:=zr;
zi0:=zi;
while (n<g) and (zr*zr+zi*zi<4) do
begin
zrh:=zr;
zr:=zr*zr-zi*zi+zr0;
zi:=zrh*zi+zi*zrh+zi0;
Inc(n) //iterations
end;
n:=Round(n+1-(log2(log2(sqrt(zr*zr+zi*zi))/log2(4)))); //<-- this should smoothen the iterations
Draw_Pixels(n,g,x,y,Image1.Canvas)
end
end;
end;
Henry
I have problems using the smooth coloring algorithm. I just don't get them implemented in my Code.
This is the main code which causes an error after some calculated pixel rows:
g:=StrToInt(Edit3.Text); //maximum iteration count
for x:=0 to Width do
begin
for y:=0 to Height do
begin
zr:=x*(br-ar)/Width+ar;
zi:=y*(bi-ai)/Height+ai;
n:=1;
zr0:=zr;
zi0:=zi;
while (n<g) and (zr*zr+zi*zi<4) do
begin
zrh:=zr;
zr:=zr*zr-zi*zi+zr0;
zi:=zrh*zi+zi*zrh+zi0;
Inc(n) //iterations
end;
n:=Round(n+1-(log2(log2(sqrt(zr*zr+zi*zi))/log2(4)))); //<-- this should smoothen the iterations
Draw_Pixels(n,g,x,y,Image1.Canvas)
end
end;
end;
Henry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您最终得到
zr == zi == 0
,您将尝试采用未定义的log2(0)
(-inf
作为限制)。如果
zr*zr+zi*zi
等于或小于 1,则内部log2
将返回 0 或负值,这将破坏外部log2
(只要处理实数就不能取负数的对数)。(而且我认为对于稍微超过 1 的
zr*zr+zi*zi
值来说,这不会平滑地缩放。)If you ever end up with
zr == zi == 0
, you'll be trying to takelog2(0)
, which is not defined (-inf
as a limit).If
zr*zr+zi*zi
is ever equal to or less than one, the innerlog2
will return 0 or a negative value, which will break the outerlog2
(can't take the log of a negative number as long as you're dealing with reals).(And I don't think that will scale smoothly for values of
zr*zr+zi*zi
slightly over 1.)