Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Pixel{
- unsigned char colors[3];
- };
- Pixel img[iYmax][iXmax];
- double nonParallel(){
- clock_t start, end;
- int iX,iY;
- double Cx,Cy;
- const double CxMin=-2.5;
- const double CxMax=1.5;
- const double CyMin=-2.0;
- const double CyMax=2.0;
- double PixelWidth=(CxMax-CxMin)/iXmax;
- double PixelHeight=(CyMax-CyMin)/iYmax;
- const int MaxColorComponentValue=255;
- FILE * fp;
- const char *filename="nonParallel.ppm";
- const char *comment="# ";/* comment should start with # */
- static unsigned char color[3];
- double Zx, Zy;
- double Zx2, Zy2; /* Zx2=Zx*Zx; Zy2=Zy*Zy */
- int Iteration;
- const int IterationMax=200;
- const double EscapeRadius=2;
- double ER2=EscapeRadius*EscapeRadius;
- /*create new file,give it a name and open it in binary mode */
- fp= fopen(filename,"wb"); /* b - binary mode */
- /*write ASCII header to the file*/
- fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
- start = clock();
- for(iY=0;iY<iYmax;iY++)
- {
- Cy=CyMin + iY*PixelHeight;
- if (fabs(Cy)< PixelHeight/2) Cy=0.0; /* Main antenna */
- for(iX=0;iX<iXmax;iX++)
- {
- Cx=CxMin + iX*PixelWidth;
- /* initial value of orbit = critical point Z= 0 */
- Zx=0.0;
- Zy=0.0;
- Zx2=Zx*Zx;
- Zy2=Zy*Zy;
- /* */
- for (Iteration=0;Iteration<IterationMax && ((Zx2+Zy2)<ER2);Iteration++)
- {
- Zy=2*Zx*Zy + Cy;
- Zx=Zx2-Zy2 +Cx;
- Zx2=Zx*Zx;
- Zy2=Zy*Zy;
- };
- /* compute pixel color (24 bit = 3 bytes) */
- if (Iteration==IterationMax)
- { /* interior of Mandelbrot set = black */
- color[0]=0;
- color[1]=0;
- color[2]=0;
- }
- else
- { /* exterior of Mandelbrot set = white */
- color[0]=255; /* Red*/
- color[1]=255; /* Green */
- color[2]=255;/* Blue */
- };
- /*write color to the file*/
- img[iY][iX].colors[0] = color[0];
- img[iY][iX].colors[1] = color[1];
- img[iY][iX].colors[2] = color[2];
- //fwrite(color,1,3,fp);
- }
- }
- end = clock();
- fwrite(img,1,sizeof(img),fp);
- fclose(fp);
- return ((double) (end - start)) / CLOCKS_PER_SEC * 1000.0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement