[go: up one dir, main page]

Jump to content

File:LCMM.jpg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikibooks, open books for an open world

Original file (2,000 × 2,000 pixels, file size: 323 KB, MIME type: image/jpeg)

Summary

Description
English: Level curves of Mandelbrot set. The Julia set boundary itself is not drawn: we see it as the locus of points where the boundaries of level curves are especially close to each other.
Source self-made using C console program
Author Adam majewski

Compare with

Long description

This is C console program.

It creates 24 bit color ( RGB ) ppm file in program directory. technic of creating ppm file is based on the code of Claudio Rocchini.

  • First dynamic 1D array for 24-bit color values is created.
  • Color of points is saved in array
  • array is saved to the file

To see the file use external application ( image viewer). File was converted from ppm to jpg.

Image is created by:

  • creating Level Sets of Escape time of Mandelbrot set ( see image Level Sets )
  • edge detection of Level sets. Algorithm is based on paper by M. Romera et al[1]

See also

C source code

It is a console C program ( one file) It can be compiled under :

  • windows ( gcc thru Dev-C++ )
  • linux and mac using gcc :
gcc main.c -lm

it creates a.out file. Then run it :

./a.out

It creates ppm file in program directory. Use file viewer to see it.

 #include <stdio.h>
 #include <math.h>
 int main()
 {
  /* screen ( integer) coordinate */
  int iX,iY;
  const int iXmax = 2000, iXmin=0; 
  const int iYmax = 2000, iYmin=0;
  int iWidth=iXmax-iXmin+1,
  iHeight=iYmax-iYmin+1,
  /* number of bytes = number of pixels of image * number of bytes of color */
  iLength=iWidth*iHeight*3,/* 3 bytes of color  */
  index; /* of array */
  /* world ( double) coordinate = parameter plane*/
  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;
  /* color component ( R or G or B) is coded from 0 to 255 */
  /* it is 24 bit color RGB file */
  const int MaxColorComponentValue=255; 
  FILE * fp;
  char *filename="LCMM.ppm";
  char *comment="# ";/* comment should start with # */
  /* Z=Zx+Zy*i  ;   Z0 = 0 */
  double Zx, Zy;
  double Zx2, Zy2; /* Zx2=Zx*Zx;  Zy2=Zy*Zy  */
  /*  */
  int Iteration, PreviousIter;
  const int IterationMax=2000;
  /* bail-out value , radius of circle ;  */
  const double EscapeRadius=1000;
  double ER2=EscapeRadius*EscapeRadius;
  /* dynamic 1D array for 24-bit color values */    
  unsigned char *array;
  /*-------------------------------------------------------------------*/
  array = malloc( iLength * sizeof(unsigned char) );
  if (array == NULL)
    {
    fprintf(stderr,"Could not allocate memory");
    getchar();
    return 1;
    }
    else 
     {   fprintf(stderr,"I'm working. Please wait (:-))\n ");
         /* fill the data array with white points */       
         for(index=0;index<iLength-1;++index) array[index]=255;
     }
  /* ---------------------------------------------------------------*/
  /* first coat of paint */
  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;
        };
       /* plot point of Level Curve */
       if (iX!=0 && Iteration!=PreviousIter)
       { 
         array[((iYmax-iY-1)*iXmax+iX)*3]=0;
         array[((iYmax-iY-1)*iXmax+iX)*3+1]=0;
         array[((iYmax-iY-1)*iXmax+iX)*3+2]=0;
         PreviousIter=Iteration;                       
       }
     }
    }
   /* second coat of paint */
   for(iX=0;iX<iXmax;iX++)
   {         
     Cx=CxMin + iX*PixelWidth;
     for(iY=0;iY<iYmax;iY++)
     {
      Cy=CyMin + iY*PixelHeight;
      if (fabs(Cy)< PixelHeight/2) Cy=0.0; /* Main antenna */
      /* 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;
       };
       /* plot point of Level Curve */
       if (iX!=0 && Iteration!=PreviousIter)
        { 
         array[((iYmax-iY-1)*iXmax+iX)*3]=0;
         array[((iYmax-iY-1)*iXmax+iX)*3+1]=0;
         array[((iYmax-iY-1)*iXmax+iX)*3+2]=0;
         PreviousIter=Iteration;                       
        }
       }
      }
   /* write the whole data array to ppm file in one step */      
   /*create new file,give it a name and open it in binary mode  */
   fp= fopen(filename,"wb"); /* b -  binary mode */
   if (fp == NULL){ fprintf(stderr,"file error"); }
     else
      {
       /*write ASCII header to the file*/
      fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
      /*write image data bytes to the file*/
      fwrite(array,iLength ,1,fp);
      fclose(fp);
      fprintf(stderr,"file saved\n");
      getchar();
     }
    free(array);
    getchar();
    return 0;
 }

Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International, 3.0 Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
You may select the license of your choice.

References

  1. Drawing the Mandelbrot set by the method of escape lines. M. Romera et al.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

copyrighted<\/a>"}},"text\/plain":{"en":{"P6216":"copyrighted"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P6216 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
Creative Commons Attribution-ShareAlike 2.0 Generic<\/a>"}},"text\/plain":{"en":{"P275":"Creative Commons Attribution-ShareAlike 2.0 Generic"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":47001652,\"id\":\"Q47001652\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P275":"Creative Commons Attribution-ShareAlike 1.0 Generic<\/a>"}},"text\/plain":{"en":{"P275":"Creative Commons Attribution-ShareAlike 1.0 Generic"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":50829104,\"id\":\"Q50829104\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P275":"Q50829104<\/a>"}},"text\/plain":{"en":{"P275":"Q50829104"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":18199165,\"id\":\"Q18199165\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P275":"Creative Commons Attribution-ShareAlike 4.0 International<\/a>"}},"text\/plain":{"en":{"P275":"Creative Commons Attribution-ShareAlike 4.0 International"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":19113751,\"id\":\"Q19113751\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P275":"Creative Commons Attribution-ShareAlike 2.5 Generic<\/a>"}},"text\/plain":{"en":{"P275":"Creative Commons Attribution-ShareAlike 2.5 Generic"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":14946043,\"id\":\"Q14946043\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P275":"Creative Commons Attribution-ShareAlike 3.0 Unported<\/a>"}},"text\/plain":{"en":{"P275":"Creative Commons Attribution-ShareAlike 3.0 Unported"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P275 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current18:41, 31 March 2008Thumbnail for version as of 18:41, 31 March 20082,000 × 2,000 (323 KB)Soul windsurfer{{Information |Description= |Source=self-made using C console program |Date= |Author= Adam majewski |Permission= |other_versions= }}

Metadata