File:LCMM.jpg
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
- LCM/J but better algorithm, ER = 2
- LSM/J B&W; ER = 1000
- LSM/J colour ( probably made with Fractint ); ER = 2
- Computed using implicit equations; ER=2
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:
![]() |
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. |
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
Category:Mandelbrot sets (whole) Category:Images with C source code Category:Complex quadratic map Category:Contour plots Category:Edge detection Category:Mandelbrot sets in grayscale
Category:CC-BY-SA-4.0,3.0,2.5,2.0,1.0
Category:Complex quadratic map
Category:Contour plots
Category:Edge detection
Category:GFDL
Category:Images with C source code
Category:License migration redundant
Category:Mandelbrot sets (whole)
Category:Mandelbrot sets in grayscale
Category:Pages using deprecated source tags
Category:Self-published work