Buddhabrot : What is wrong in this algo?

Hey,

I’m working in buddhabrot and I have a little issue in my algorithm and I don’t know how I can fix it.
I followed lot of pseudo code in Google but it’s not enough…
Can you help me?

I think my problem is when I saved coordinate in my tmp_pixels…

(All this code, like one while with incremental position etc… is normal because I’m working in other langage. I created this code in processing to get help)

double xmin = -2.5;
double ymin = -2;
double wh = 4;
int maxiterations = 200;

void setup() {
  size(512,512); 
  loadPixels();
  int resolution = 512;
  
  double xmax = xmin + wh;
  double ymax = ymin + wh;
  double cImaginary = ymin;
  double cReal = 0;
  
  int positionX = 0;
  int positionY = 0;

  // Calculate amount we increment x,y for each pixel
  double dx = (xmax-xmin) / resolution;
  double dy = (ymax-ymin) / resolution;
  
  int[][] myPixels = new int[resolution][resolution];
  for (int i = 0; i < resolution; i++) {
    for (int j = 0; j < resolution; j++) {
      myPixels[i][j] = 0;
    }
  } 
  
  while(positionY < resolution)
  {           
      double real = 0;
      double imaginary = 0;      
      int n = 0;
      ArrayList<PVector> tmp_pixels = new ArrayList<PVector>();
      
      while (n < maxiterations) 
      {  
        double tmp = real;        
        real = real * real - imaginary * imaginary + cReal; 
        imaginary = 2 * imaginary * tmp + cImaginary; 
        
        if ((real * real) + (imaginary * imaginary) > 16.0) {
          break;
        }
        
        tmp_pixels.add(new PVector((int)real,(int)imaginary));        
        n++;
      }

      if (n != maxiterations)
      {
        for (PVector pixel : tmp_pixels) {
            
          if(pixel.x < resolution && pixel.y < resolution && pixel.x >= 0 && pixel.y >= 0) {
                      
             myPixels[(int)pixel.x][(int)pixel.y]++;
          } 
        }
         
      } 
    
      
      positionX = positionX + 1;
      cReal += dx; 
      
      if(positionX >= resolution){
         positionX = 0;
         positionY = positionY + 1;
         cImaginary += dy;
         cReal = xmin;
      }
       
    
    }
  
 for(int i = 0; i < resolution; i++)
 {
   for(int j = 0; j < resolution; j++)
   {
     int value = myPixels[i][j];
     pixels[i+j*resolution] = color(value,value,value);
   }
 }
  
  updatePixels();
}