我还是比较新的Java。我一直致力于一个显示mandelbrot集的程序。我当前的代码生成的图像很接近,但不完全是mandelbrot集。这是我的代码:
private void generateMap () {
// scale, ITERATIONS, map, and SIZE are class variables
// cR and cI are the actual coordinates in the set being used
double cR = -2*scale;
double cI = -2*scale;
// a and b step through the array used to store the drawing
// and control when the loop exits
for (int a = 0; a < SIZE.width; a++)
{
for (int b = 0; b < SIZE.height; b++)
{
double xR = 0;
double xI = 0;
int iter = 0;
while (iter < ITERATIONS)
{
xR = (xR*xR-xI*xI) + cR;
xI = (2*xR*xI) + cI;
if (xR*xR+xI*xI > 4) {
map[a][b] = iter;
iter = ITERATIONS;
}
iter++;
}
cI += INCREMENT*scale;
}
cI = -2*scale;
cR += INCREMENT*scale;
}
}
我的netbeans项目可从here下载。
这是当前输出的屏幕截图:
答案 0 :(得分:0)
xR和xI的新值未一致计算。 xR基于其先前值计算,而xI基于xR的新值计算。尝试类似下面的内容,或者使用复杂的数字类。
double r = xR;
double i = xI;
xR = (r*r-i*i) + cR;
xI = (2*r*i) + cI;