在 Android 上为 Mandelbrot 集着色时出现问题
我在为 Mandelbrot 集着色时遇到问题。 这是我的 onDraw() 过程:
@Override
protected void onDraw(Canvas canvas) {
g = Math.round(60+(iter_count*(2500/16)));
iter_count++;
for(int xx = 1; xx <= xMax; xx++) {
for(int yy = 1; yy <= yMax; yy++) {
schirmzupap(ar,br,bi,ai,xx,yy,xMax,yMax);
n = 1;
zr0 = zr;
zi0 = zi;
while ((n<g) && (zr*zr+zi*zi<4)) {
zrh = zr;
zr = (zr*zr)-zi*zi+zr0;
zi = zrh*zi+zi*zrh+zi0;
n++;
}
if (n==g) { //[Coloring]
paint.setARGB(255,0,0,0);
}
if ((n/g) < (1/2)) {
paint.setARGB(255,Math.round((n/g)*255),0,0);
}
if (((n/g) < 1) && ((n/g) > 1/2)) {
paint.setARGB(255,255,Math.round((n/g)*255),Math.round((n/g)*255));
}
canvas.drawPoint(xx, yy, paint); //[/Coloring]
}
}
}
这是 Java Android 模拟器的外观:http://i55。 tinypic.com/14ctqi8.png
这就是我希望它的外观:http://i54.tinypic.com/nh1aqe.png 它是用Delphi编写的,但着色部分实际上是相同的:
if n=g then image1.canvas.Pixels[xx,yy]:=RGB2TColor(0,0,0);
if (n/g)<(1/2) then image1.canvas.Pixels[xx,yy]:=RGB2TColor(Round((n/g)*255),0,0);
if ((n/g)<(1)) AND ((n/g)>(1/2)) then image1.canvas.Pixels[xx,yy]:=RGB2TColor(255,Round((n/g)*255),Round((n/g)*255));
有人可以帮助我吗? 格雷兹
亨利·
I have a problem with coloring the Mandelbrot set.
This is my onDraw() procedure:
@Override
protected void onDraw(Canvas canvas) {
g = Math.round(60+(iter_count*(2500/16)));
iter_count++;
for(int xx = 1; xx <= xMax; xx++) {
for(int yy = 1; yy <= yMax; yy++) {
schirmzupap(ar,br,bi,ai,xx,yy,xMax,yMax);
n = 1;
zr0 = zr;
zi0 = zi;
while ((n<g) && (zr*zr+zi*zi<4)) {
zrh = zr;
zr = (zr*zr)-zi*zi+zr0;
zi = zrh*zi+zi*zrh+zi0;
n++;
}
if (n==g) { //[Coloring]
paint.setARGB(255,0,0,0);
}
if ((n/g) < (1/2)) {
paint.setARGB(255,Math.round((n/g)*255),0,0);
}
if (((n/g) < 1) && ((n/g) > 1/2)) {
paint.setARGB(255,255,Math.round((n/g)*255),Math.round((n/g)*255));
}
canvas.drawPoint(xx, yy, paint); //[/Coloring]
}
}
}
This is how it looks at the Java Android emulator: http://i55.tinypic.com/14ctqi8.png
This is how I want it to look: http://i54.tinypic.com/nh1aqe.png It's written in Delphi, but the coloring part is actually the same:
if n=g then image1.canvas.Pixels[xx,yy]:=RGB2TColor(0,0,0);
if (n/g)<(1/2) then image1.canvas.Pixels[xx,yy]:=RGB2TColor(Round((n/g)*255),0,0);
if ((n/g)<(1)) AND ((n/g)>(1/2)) then image1.canvas.Pixels[xx,yy]:=RGB2TColor(255,Round((n/g)*255),Round((n/g)*255));
Could someone help me please?
Greetz,
Henry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
onDraw
中进行复杂的计算。else if
会更清晰。看来第三个胜过第二个……?转换为双精度
记住整数除法,例如
25000 / 25600
将== 0
,因此所有这些像素将得到 (255 ,0,0)onDraw
if it can be helped.Math.floor()
instead of round in these instances, as you don't really want things to be rounded upwards here.else if
for the second and third conditions of your colouring algorithm. It seems that the third one is winning out over the second...?n
andg
as integers! The divisions will be integer divisions unless you do this:convert to double
Remember an integer division e.g.
25000 / 25600
will== 0
, and therefore all those pixels will get (255,0,0)正如桑杰所说,你的分裂有问题。
你可以用 Sanjay 的方式修复。但注意1/2=0 1.0/2=0.5。
或者可读性较差但速度
更快
As Sanjay said your have a problem with division.
You could fix in Sanjay-way. But take attention 1/2=0 1.0/2=0.5.
Or less readeble but a bit faster
and