// Does the math to generate the Mandelbrot grid. private void generateIterCounts() { for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { Complex z = new Complex(0, 0); Complex c = new Complex(xStart + (dx * j), yStart + (dy * i)); int iters = 0; while(true) { z = z.Times(z).Plus(c); iters++; // Exit while loop when either divergence is shown, // or enough iterations through loop happened that // divergence is unlikely. if(z.Modulus() >= maxModulus || iters >= maxIters) break; } if(iters >= maxIters) // Set point to 0 to signify no divergence. data[i, j] = 0; else // Set point to the number of iterations required to show divergence. data[i, j] = iters; } } }