Advertisement
TheGhastModding

Mandelbrot

Mar 1st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1.     double re = -0.235125;
  2.     double imag = 0.827215;
  3.     double r = 4.0e-5;
  4.    
  5.     const int maxIters = 2048;
  6.     double c_re;
  7.     double c_im;
  8.     double x;
  9.     double y;
  10.     int iteration;
  11.     const double c1 = 4.0/width*r;
  12.     const double c2 = width/2.0*c1;
  13.     const double c3 = height/2.0*c1;
  14.     double xx;
  15.     double yy;
  16.    
  17.     for(int row = 0; row < height; row++){
  18.         c_im = imag + (row * c1) - c3;
  19.         for(int col = 0; col < width; col++){
  20.             c_re = re + (col * c1) - c2;
  21.             x = 0; y = 0;
  22.             iteration = 0;
  23.             do {
  24.                 xx = x*x;
  25.                 yy = y*y;
  26.                 y = x*y;
  27.                 y += y;
  28.                 y += c_im;
  29.                 x = xx - yy + c_re;
  30.                 iteration++;
  31.             }while(xx+yy <= 4 && iteration < maxIters);
  32.             if(iteration < maxIters){
  33.                 //Calculate a color from the value of the "iteration" variable and set the pixel color to that
  34.                 //I use int rgb = HSBtoRGB((float)iteration/256.0f, 1.0f, (float)iteration/(iteration+8.0f));
  35.                 //But idk if that's a thing in JS
  36.             }else{
  37.                 //pixel Color = black (RGB 0,0,0)
  38.             }
  39.  
  40.         }
  41.         PORTD ^= (1 << PD4);
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement