awt - Mandelbrot set in java doesn't calculate correctly -


i'm still relatively new java. i've been working on program display mandelbrot set. current code generates image close, not quite mandelbrot set. generation code:

private void generatemap () {     // scale, iterations, map, , size class variables     // cr , ci actual coordinates in set being used     double cr = -2*scale;     double ci = -2*scale;     // , b step through array used store drawing     // , control when loop exits     (int = 0; < size.width; a++)      {         (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;     } } 

my netbeans project downloadable here.

here's screenshot of current output: screenshot

the new values of xr , xi not being calculated consistently. xr calculated based on previous value while xi calculated based on xr's new value. try following or maybe use complex number class.

double r = xr; double = xi; xr = (r*r-i*i) + cr; xi = (2*r*i) + ci; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -