Guest User

Untitled

a guest
Apr 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.     public Mandelbrot(int rows, int cols, Complex topLeftCorner, double xStepSize, double yStepSize, int maxIterations, RGBColor[] palette){
  2.         Complex[][] plane = new Complex[rows][cols];
  3.  
  4.     for (int i=0;i<rows;i++){
  5.         for (int j=0;j<cols;j++){  
  6.             Complex deltaFromTopLeft = new Complex(j*xStepSize,-i*yStepSize);
  7.             plane[i][j]= topLeftCorner.plus(deltaFromTopLeft);
  8.             }
  9.         }
  10.         complex = plane;
  11.                 // this is a shallow copy, do a deep copy
  12.         this.palette = palette;
  13.         this.rows = rows;
  14.         this.cols = cols;
  15.         this.maxIterations=maxIterations;
  16.     }
  17.  
  18.     public RGBImage getImage(){
  19.         image = new RGBImage(rows, cols);
  20.         for (int i=0;i<rows;i++){
  21.             for (int j=0;j<cols;j++){
  22.             int paletteIndex = complex[i][j].escapeTime(RADIUS, maxIterations);
  23.                 if (paletteIndex==-1){
  24.                     paletteIndex=0;
  25.                 }
  26.                 image.setPixel(i, j, palette[paletteIndex]);
  27.             }
  28.         }
  29.        
  30.         return image;
  31.     }
  32. }
Add Comment
Please, Sign In to add comment