Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. struct Pixel{
  2.     unsigned char colors[3];
  3. };
  4.  
  5. Pixel img[iYmax][iXmax];
  6.  
  7. double nonParallel(){
  8.     clock_t start, end;
  9.     int iX,iY;
  10.     double Cx,Cy;
  11.     const double CxMin=-2.5;
  12.     const double CxMax=1.5;
  13.     const double CyMin=-2.0;
  14.     const double CyMax=2.0;
  15.     double PixelWidth=(CxMax-CxMin)/iXmax;
  16.     double PixelHeight=(CyMax-CyMin)/iYmax;
  17.     const int MaxColorComponentValue=255;
  18.     FILE * fp;
  19.     const char *filename="nonParallel.ppm";
  20.     const char *comment="# ";/* comment should start with # */
  21.     static unsigned char color[3];
  22.     double Zx, Zy;
  23.     double Zx2, Zy2; /* Zx2=Zx*Zx;  Zy2=Zy*Zy  */
  24.     int Iteration;
  25.     const int IterationMax=200;
  26.     const double EscapeRadius=2;
  27.     double ER2=EscapeRadius*EscapeRadius;
  28.     /*create new file,give it a name and open it in binary mode  */
  29.     fp= fopen(filename,"wb"); /* b -  binary mode */
  30.     /*write ASCII header to the file*/
  31.     fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
  32.    
  33.     start = clock();
  34.     for(iY=0;iY<iYmax;iY++)
  35.     {
  36.          Cy=CyMin + iY*PixelHeight;
  37.          if (fabs(Cy)< PixelHeight/2) Cy=0.0; /* Main antenna */
  38.          for(iX=0;iX<iXmax;iX++)
  39.          {        
  40.                     Cx=CxMin + iX*PixelWidth;
  41.                     /* initial value of orbit = critical point Z= 0 */
  42.                     Zx=0.0;
  43.                     Zy=0.0;
  44.                     Zx2=Zx*Zx;
  45.                     Zy2=Zy*Zy;
  46.                     /* */
  47.                     for (Iteration=0;Iteration<IterationMax && ((Zx2+Zy2)<ER2);Iteration++)
  48.                     {
  49.                         Zy=2*Zx*Zy + Cy;
  50.                         Zx=Zx2-Zy2 +Cx;
  51.                         Zx2=Zx*Zx;
  52.                         Zy2=Zy*Zy;
  53.                     };
  54.                     /* compute  pixel color (24 bit = 3 bytes) */
  55.                     if (Iteration==IterationMax)
  56.                     { /*  interior of Mandelbrot set = black */
  57.                        color[0]=0;
  58.                        color[1]=0;
  59.                        color[2]=0;                          
  60.                     }
  61.                  else
  62.                     { /* exterior of Mandelbrot set = white */
  63.                          color[0]=255; /* Red*/
  64.                          color[1]=255;  /* Green */
  65.                          color[2]=255;/* Blue */
  66.                     };
  67.                     /*write color to the file*/
  68.                     img[iY][iX].colors[0] = color[0];
  69.                     img[iY][iX].colors[1] = color[1];
  70.                     img[iY][iX].colors[2] = color[2];
  71.                     //fwrite(color,1,3,fp);
  72.             }
  73.     }
  74.     end = clock();
  75.     fwrite(img,1,sizeof(img),fp);
  76.     fclose(fp);
  77.     return ((double) (end - start)) / CLOCKS_PER_SEC * 1000.0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement