我对 Java 还是比较陌生。我一直在研究一个显示曼德布罗集的程序。我当前的代码生成了一个接近的图像,但不完全是 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 项目可以从这里下载。
这是当前输出的屏幕截图: