File:Cubic Julia set C =-0.040000000000000036-0.78*I with internal level curves.png

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

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

Captions

Captions

Cubic Julia set C =-0.040000000000000036-0.78*I with internal level curves

Summary

[edit]
Description
English: Cubic Julia set where c =-0.040000000000000036-0.78*I with internal level curves. Location by Roger Lee Bagula - here. The Julia set (boundary of filled-n Julia set) itself is not drawn: we see it as the locus of points where the level curves (= the boundaries of level sets) are especially close to each other = a place with high density of level curves. One can see also spiral from attracting point to repelling fixed point which is a place with high density of level curves. Points of critical orbit ( including crirital point and attractor) are on the level curves like notes on the musical staff. Level curves cross at critical point and its preimages.
Date
Source Own work
Author Adam majewski

Licensing

[edit]
I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International 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.

description of the map

[edit]
coefficients read from input file cubic_p2_Bagula.txt
	degree 3 coefficient = ( +1.0000000000000000 +0.0000000000000000*i) 
	degree 2 coefficient = ( +0.0000000000000000 +0.0000000000000000*i) 
	degree 1 coefficient = ( +0.0000000000000000 +0.0000000000000000*i) 
	degree 0 coefficient = ( -0.0400000000000000 -0.7800000000000000*i) 

Input polynomial p(z)=(1+0i)*z^3+(-0.040000000000000035527-0.78000000000000002665i)

derivative dp/dz = (3+0i)*z^2

2 critical points found

cp#0: -2.2351741790771484375e-08,-2.2351741790771484375e-08 . It's critical orbit is bounded and enters cycle #0 length=2 
      and it's stability = |multiplier|=0.95704 =attractive 
      internal angle = 0.045777099465243623055
      cycle = { 0.12845610612214106161,-0.42699144182978676643 ; -0.108141353107358687,-0.7232875185669475071 ; }

cp#1: -2.2351741790771484375e-08,9.4296410679817199707e-09 . It's critical orbit is bounded  and enters cycle #0


one can check using Maxima CAS that there is only one critical point z=0

%i1) f:z^3+c;
                                     3
(%o1)                               z  + c
(%i2) diff(f,z,1);
                                        2
(%o2)                                3 z
(%i3) solve(3*z^2=0);
(%o3)                               [z = 0]

text output of c program

[edit]
make
chmod +x d.sh
./d.sh
make pgm files 
display OMP info 

OPENMP DISPLAY ENVIRONMENT BEGIN
  _OPENMP = '201511'
  OMP_DYNAMIC = 'FALSE'
  OMP_NESTED = 'FALSE'
  OMP_NUM_THREADS = '8'
  OMP_SCHEDULE = 'DYNAMIC'
  OMP_PROC_BIND = 'FALSE'
  OMP_PLACES = ''
  OMP_STACKSIZE = '0'
  OMP_WAIT_POLICY = 'PASSIVE'
  OMP_THREAD_LIMIT = '4294967295'
  OMP_MAX_ACTIVE_LEVELS = '2147483647'
  OMP_CANCELLATION = 'FALSE'
  OMP_DEFAULT_DEVICE = '0'
  OMP_MAX_TASK_PRIORITY = '0'
  OMP_DISPLAY_AFFINITY = 'FALSE'
  OMP_AFFINITY_FORMAT = 'level %L thread %i affinity %A'
OPENMP DISPLAY ENVIRONMENT END
setup start
 end of setup 
 allways free memory (deallocate )  to avoid memory leaks 

real	4m13,453s
user	31m19,822s
sys	0m2,909s
convert all pgm files to png using Image Magic convert 
FatouAnd B.pgm
Fatou_b.pgm
Fatou.pgm
LCM_9.pgm
LCM_cr.pgm
LSM_9.pgm
LSM_a.pgm
delete all pgm files 
OK

c source code

[edit]
/*




  Adam Majewski
  adammaj1 aaattt o2 dot pl  // o like oxygen not 0 like zero 
  
  
  
  Structure of a program or how to analyze the program 
  
  
  ============== Image X ========================
  
  DrawImageOfX -> DrawPointOfX -> ComputeColorOfX 
  
  first 2 functions are identical for every X
  check only last function =  ComputeColorOfX
  which computes color of one pixel !
  
  

   
  ==========================================

  
  ---------------------------------
  indent d.c 
  default is gnu style 
  -------------------



  c console progam 
  
  export  OMP_DISPLAY_ENV="TRUE"	
  gcc d.c -lm -Wall -march=native -fopenmp
  time ./a.out > b.txt


  gcc d.c -lm -Wall -march=native -fopenmp


  time ./a.out

  time ./a.out >i.txt
  time ./a.out >e.txt
  
  
  
  
  
  
  convert -limit memory 1000mb -limit disk 1gb dd30010000_20_3_0.90.pgm -resize 2000x2000 10.png

  
  
  
*/

#include <stdio.h>
#include <stdlib.h>		// malloc
#include <string.h>		// strcat
#include <math.h>		// M_PI; needs -lm also
#include <complex.h>
#include <omp.h>		// OpenMP
#include <limits.h>		// Maximum value for an unsigned long long int



// https://sourceforge.net/p/predef/wiki/Standards/

#if defined(__STDC__)
#define PREDEF_STANDARD_C_1989
#if defined(__STDC_VERSION__)
#if (__STDC_VERSION__ >= 199409L)
#define PREDEF_STANDARD_C_1994
#endif
#if (__STDC_VERSION__ >= 199901L)
#define PREDEF_STANDARD_C_1999
#endif
#endif
#endif




/* --------------------------------- global variables and consts ------------------------------------------------------------ */


//FunctionType
typedef enum  {Fatou = 0, IntLSM =1 , ExtLSM = 2, LSM = 3, DEM = 4, Unknown = 5 , BD = 6, MBD = 7 , SAC = 8, DLD = 9, ND = 10 , NP= 11, POT = 12 , Blend = 13
		
} FunctionTypeT; 
// FunctionTypeT FunctionType;

// virtual 2D array and integer ( screen) coordinate
// Indexes of array starts from 0 not 1 
//unsigned int ix, iy; // var
static unsigned int ixMin = 0;	// Indexes of array starts from 0 not 1
static unsigned int ixMax;	//
static unsigned int iWidth;	// horizontal dimension of array

static unsigned int iyMin = 0;	// Indexes of array starts from 0 not 1
static unsigned int iyMax;	//

static unsigned int iHeight = 20000;	//  
// The size of array has to be a positive constant integer 
static unsigned long long int iSize;	// = iWidth*iHeight; 

// memmory 1D array 
unsigned char *data;
unsigned char *edge;
//unsigned char *edge2;

// unsigned int i; // var = index of 1D array
//static unsigned int iMin = 0; // Indexes of array starts from 0 not 1
static unsigned int iMax;	// = i2Dsize-1  = 
// The size of array has to be a positive constant integer 
// unsigned int i1Dsize ; // = i2Dsize  = (iMax -iMin + 1) =  ;  1D array with the same size as 2D array



// see SetPlane

double radius = 1.5; 
complex double center = 0.0;
double  DisplayAspectRatio  = 1.0; // https://en.wikipedia.org/wiki/Aspect_ratio_(image)
// dx = dy compare setup : iWidth = iHeight;
double ZxMin; //= -1.3;	//-0.05;
double ZxMax;// = 1.3;	//0.75;
double ZyMin;// = -1.3;	//-0.1;
double ZyMax;// = 1.3;	//0.7;
double PixelWidth;	// =(ZxMax-ZxMin)/ixMax;
double PixelHeight;	// =(ZyMax-ZyMin)/iyMax;

double ratio; 


/*
  ER = pow(10,ERe);
  AR = pow(10,-ARe);
*/
//int ARe ;			// increase ARe until black ( unknown) points disapear 
//int ERe ;
double ER;
double ER2;			//= 1e60;
double AR; // bigger values do not works
double AR2;

double AR_max;
//double AR12;



int IterMax = 100000;
int IterMax_LSM = 1000;


/* colors = shades of gray from 0 to 255 

   unsigned char colorArray[2][2]={{255,231},    {123,99}};
   color = 245;  exterior 
*/
unsigned char iColorOfExterior = 245;
unsigned char iColorOfInterior1 = 99;
unsigned char iColorOfInterior2 = 183;
unsigned char iColorOfBoundary = 0;
unsigned char iColorOfUnknown = 5;

// pixel counters
unsigned long long int uUnknown = 0;
unsigned long long int uInterior = 0;
unsigned long long int uExterior = 0;



// critical points




// critical points
complex double zcr = 0.0; // only one critical point 
//complex double zc2 = -2.2351741790771484375e-08+9.4296410679817199707e-09*I;


/*

  

*/



/* Roger Lee Bagula z^3 + C
c, z1, z2, z3 = -0.040000000000000036-0.78i, 0, 0, 1

-0.040000000000000036-0.78i, 0, 0, 1
for 
https://www.marksmath.org/visualization/polynomial_julia_sets/
*/
const complex double C =-0.040000000000000036-0.78*I;
const int period = 2;

// periodic points = attractors
complex double z2a =  0.128494244956895 -0.427153520116896*I ; //first point of period  2 attracting cycle
complex double z2b = -0.108213690768581 -0.723219415137925*I ; //second point of  period 2 attracting cycle


/* ------------------------------------------ functions -------------------------------------------------------------*/


// complex function
complex double fc(const complex double z0, const complex double c) {

	double complex z = z0;
	z = z*z*z + c;
	return  z;
	}
	

// iterated function
complex double Fpc(const complex double z0, const complex double c, const int period) {

	int p;
	int pMax = period;
	double complex z = z0;
	
	for (p=0; p< pMax; ++p ){
	
		z = fc(z,c);}
	return z;
	}
		








//------------------complex numbers -----------------------------------------------------





// from screen to world coordinate ; linear mapping
// uses global cons
double
GiveZx (int ix)
{
  return (ZxMin + ix * PixelWidth);
}

// uses globaal cons
double
GiveZy (int iy)
{
  return (ZyMax - iy * PixelHeight);
}				// reverse y axis


complex double
GiveZ (int ix, int iy)
{
  double Zx = GiveZx (ix);
  double Zy = GiveZy (iy);

  return Zx + Zy * I;




}



double cabs2(complex double z){

  return creal(z)*creal(z)+cimag(z)*cimag(z);


}




/* find such AR for internal LCM/J and LSM that level curves croses critical point and it's preimages
for attracting ( also weakly attracting = parabolic) dynamics

it may fail if one iteration is bigger then smallest distance between periodic point and Julia set
*/
double GiveTunedAR(const int iter_Max, const double complex c , const double AR_max){

  fprintf(stdout, " GiveTunedAR\n");

  complex double z = zcr; // initial point z0 = criical point 
  int iter;
  double r; 
  //int i_Max = 1000;
  
  for (iter=0; iter< iter_Max; ++iter ){
  // period !!!
  	r = cabs(z-z2a);
  	fprintf(stdout, " i = %d z = %f %+f \t r = %f = %d * pixeWidth \n",iter , creal(z), cimag(z),   r, (int) (r/PixelWidth));
  	
  	z = fc(z,c); // forward iteration
  	
  
  }
  
  
  r = cabs(z-z2a);
  fprintf(stdout, "  r = %f = %d * pixeWidth \n",  r, (int) (r/PixelWidth));
  if ( r> cabs(z-z2b)) 
  	{ 	fprintf(stdout, "one more forward iteration \n");
  		z = fc(z,c); 
  		r = cabs(z-z2a);
  	}
  
  
  if ( r > AR_max ) 
  	{
  		fprintf(stdout, " AR_max < r = %f = %d * pixeWidth \n",  r, (int) (r/PixelWidth));
  		fprintf(stdout, " increase i_max\n" );
  	  r = AR_max;}	// manual check
	 

	 
 return r;
	
	
}






// =====================
int IsPointInsideTrap1(complex double  z){

	
	 
	
  if ( cabs2(z - z2a) < AR2 ) {return 1;} // circle around z2a 
  
  
  return 0; // outside



}




// =====================
int IsPointInsideTrap2(complex double  z){

	
	 
	
  if ( cabs2(z - z2b) < AR2 ) {return 1;} // circle around z2b
  
  
  return 0; // outside



}


int IsPointInsideTraps(complex double  z){

	
	 
	
  if ( IsPointInsideTrap1(z)  || IsPointInsideTrap2(z)) {return 1;} // 
	
  
	
  return 0; // outside



}



// =====================
int IsPixelInsideTraps(unsigned int ix, unsigned int iy){

	
  complex double  z = GiveZ (ix, iy);
	
  if ( IsPointInsideTraps(z) ) {return 1;} // 
	
  
	
  return 0; // outside



}




// ****************** DYNAMICS = trap tests ( target sets) ****************************


/* -----------  array functions = drawing -------------- */

/* gives position of 2D point (ix,iy) in 1D array  ; uses also global variable iWidth */
unsigned int
Give_i (unsigned int ix, unsigned int iy)
{
  return ix + iy * iWidth;
}



// f(z)=1+z−3z2−3.75z3+1.5z4+2.25z5
unsigned char
ComputeColorOfFatou (complex double z)
{



	
	
  double r2;


  int i;			// number of iteration
  for (i = 0; i < IterMax; ++i)
    {


		
	
        r2 =cabs2(z);
		
      if (r2 > ER2) // esaping = exterior
	{
	  uExterior += 1;
	  return iColorOfExterior;
	}			
	
      // solid color for each Fatou components
	
      if ( IsPointInsideTrap1(z)) {
	uInterior +=1;
	if ( i % period ) 
		{return iColorOfInterior1;}
		else {return iColorOfInterior2;}
      } // 50 + (i % 114); }
	
	z = fc(z,C);		// complex iteration f(z)=z^3 + c

    }

  uUnknown += 1;
  return iColorOfUnknown;


}




// f(z)=1+z−3z2−3.75z3+1.5z4+2.25z5
unsigned char
ComputeColorOfLSM (complex double z)
{



	
	
  double r2;


  int i;			// number of iteration
  for (i = 0; i < IterMax_LSM; ++i)
    {


		

     	// complex iteration f(z)=z^3 + c
            r2 =cabs2(z);
		
      if (r2 > ER2) // esaping = exterior
	{
	  uExterior += 1;
	  return 255- ((i*15) % 255);
	}			
	
      // solid color for each Fatou components
	
      if ( IsPointInsideTrap1(z)) {
	uInterior +=1;
	if ( i % 2 ) 
		{return (i*9) % 255  ;}
		else {return (i*10) % 255;}
      } // 50 + (i % 114); }
	
	 z = fc(z,C);	

    }

  uUnknown += 1;
  return iColorOfUnknown;


}




/* ==================================================================================================
   ============================= Draw functions ===============================================================
   =====================================================================================================
*/ 
unsigned char ComputeColor(FunctionTypeT FunctionType, complex double z){

  unsigned char iColor;
	
	
	
  switch(FunctionType){
  
  case Fatou :{iColor = ComputeColorOfFatou(z); break;}
  
 
 // case IntLSM :{iColor = ComputeColorOfIntLSM(z); break;}
	
 // case ExtLSM :{iColor = ComputeColorOfExtLSM(z); break;}
  
  case LSM :{iColor = ComputeColorOfLSM(z); break;}
  
  /*
		
  case DEM : {iColor = ComputeColorOfDEM(z); break;}
		
  case Unknown : {iColor = ComputeColorOfUnknown(z); break;}
		
  case BD : {iColor = ComputeColorOfBD(z); break;}
		
  case MBD : {iColor = ComputeColorOfMBD(z); break;}
		
  case SAC : {iColor = ComputeColorOfSAC(z); break;}
  
  case DLD : {iColor = ComputeColorOfDLD(z); break;}
		
  case ND : {iColor = ComputeColorOfND(z); break;}
		
  case NP : {iColor = ComputeColorOfNP(z); break;}
		
  case POT : {iColor = ComputeColorOfPOT(z); break;}
		
  case Blend : {iColor = ComputeColorOfBlend(z); break;}
  */		
	
  default: {}
	
	
  }
	
  return iColor;



}


// plots raster point (ix,iy) 
int DrawPoint ( unsigned char A[], FunctionTypeT FunctionType, int ix, int iy)
{
  int i;			/* index of 1D array */
  unsigned char iColor;
  complex double z;


  i = Give_i (ix, iy);		/* compute index of 1D array from indices of 2D array */
  
  z = GiveZ(ix,iy);
  

  iColor = ComputeColor(FunctionType, z);
  A[i] = iColor ;		// 
  
  return 0;
}




int
DrawImage ( unsigned char A[], FunctionTypeT FunctionType)
{
  unsigned int ix, iy;		// pixel coordinate 

  fprintf (stdout, "compute Fatou image LSM\n");
  // for all pixels of image 
#pragma omp parallel for schedule(dynamic) private(ix,iy) shared(A, ixMax , iyMax, uUnknown, uInterior, uExterior)
  for (iy = iyMin; iy <= iyMax; ++iy)
    {
      fprintf (stderr, " %d from %d \r", iy, iyMax);	//info 
      for (ix = ixMin; ix <= ixMax; ++ix)
	DrawPoint(A, FunctionType, ix, iy);	//  
    }

  return 0;
}





int IsInside (int x, int y, int xcenter, int ycenter, int r){

	
  double dx = x- xcenter;
  double dy = y - ycenter;
  double d = sqrt(dx*dx+dy*dy);
  if (d<r) 
    return 1;
  return 0;
	  

} 

int PlotBigPoint(complex double z, unsigned char A[]){

	
  unsigned int ix_seed = (creal(z)-ZxMin)/PixelWidth;
  unsigned int iy_seed = (ZyMax - cimag(z))/PixelHeight;
  unsigned int i;
	
	
  /* mark seed point by big pixel */
  int iSide =2.0*iWidth/2000.0 ; /* half of width or height of big pixel */
  int iY;
  int iX;
  for(iY=iy_seed-iSide;iY<=iy_seed+iSide;++iY){ 
    for(iX=ix_seed-iSide;iX<=ix_seed+iSide;++iX){ 
      if (IsInside(iX, iY, ix_seed, iy_seed, iSide)) {
	i= Give_i(iX,iY); /* index of _data array */
	A[i]= 0; //255-A[i];
	}}}
	
	
  return 0;
	
}


// fill array 
// uses global var :  ...
// scanning complex plane 
int MarkAttractors (unsigned char A[])
{
  
	
	
	
  fprintf (stdout, "mark attractors \n");
  
  PlotBigPoint(z2a, A); // period 114  cycle
  PlotBigPoint(z2b, A);	// period 2 attracting cycle
    		 
      	

  return 0;
}






int MarkTraps(unsigned char A[]){

  unsigned int ix, iy;		// pixel coordinate 
  unsigned int i;


  fprintf (stdout ,"Mark traps \n");
  // for all pixels of image 
#pragma omp parallel for schedule(dynamic) private(ix,iy) shared(A, ixMax , iyMax, uUnknown, uInterior, uExterior)
  for (iy = iyMin; iy <= iyMax; ++iy)
    {
      fprintf (stdout, " %d from %d \r", iy, iyMax);	//info 
      for (ix = ixMin; ix <= ixMax; ++ix){
	if (IsPixelInsideTraps(ix, iy)) {
	  i= Give_i(ix,iy); /* index of _data array */
	  A[i]= 255-A[i]; // inverse color
	}}}
  return 0;
}






int PlotPoint(complex double z, unsigned char A[]){

	
  unsigned int ix = (creal(z)-ZxMin)/PixelWidth;
  unsigned int iy = (ZyMax - cimag(z))/PixelHeight;
  unsigned int i = Give_i(ix,iy); /* index of _data array */
	
	
  A[i]= 0; //255-A[i]; // Mark point with inveres color
	
	
  return 0;
	
}


int DrawForwardOrbit(complex double z, unsigned long long int iMax,  unsigned char A[] )
{
  
  unsigned long long int i; /* nr of point of critical orbit */
  printf("draw forward orbit \n");
 
  PlotBigPoint(z, A);
  
  /* forward orbit of critical point  */
  for (i=1;i<iMax ; ++i)
    {
      z  = fc(z,C);
      //if (cabs2(z - z2a) > 2.0) {return 1;} // escaping
      PlotBigPoint(z, A);
    }
  

    
   
  return 0;
 
}


int Test(){


 complex double z = zcr;
 int i;
 int iMax = 100;
 
 printf(" |z-z2a| = %f \t |z-z2b| = %f \n", cabs(z-z2a),  cabs(z-z2b)); 
 	
	/* forward orbit of critical point  */
  for (i=1;i<iMax ; ++i)
    {
      z  = fc(z,C);
      printf("z = %f%+f \t |z-z2a| = %f \t |z-z2b| = %f \n", creal(z), cimag(z), cabs(z-z2a),  cabs(z-z2b)); 
 	
      
      //if (cabs2(z - z2a) > 2.0) {return 1;} // escaping
      
    }
    
    return 0;
  


}





// ***********************************************************************************************
// ********************** edge detection usung Sobel filter ***************************************
// ***************************************************************************************************

// from Source to Destination
int ComputeBoundaries(unsigned char S[], unsigned char D[])
{
 
  unsigned int iX,iY; /* indices of 2D virtual array (image) = integer coordinate */
  unsigned int i; /* index of 1D array  */
  /* sobel filter */
  unsigned char G, Gh, Gv; 
  // boundaries are in D  array ( global var )
 
  // clear D array
  memset(D, iColorOfExterior, iSize*sizeof(*D)); // for heap-allocated arrays, where N is the number of elements = FillArrayWithColor(D , iColorOfExterior);
 
  // printf(" find boundaries in S array using  Sobel filter\n");   
#pragma omp parallel for schedule(dynamic) private(i,iY,iX,Gv,Gh,G) shared(iyMax,ixMax)
  for(iY=1;iY<iyMax-1;++iY){ 
    for(iX=1;iX<ixMax-1;++iX){ 
      Gv= S[Give_i(iX-1,iY+1)] + 2*S[Give_i(iX,iY+1)] + S[Give_i(iX-1,iY+1)] - S[Give_i(iX-1,iY-1)] - 2*S[Give_i(iX-1,iY)] - S[Give_i(iX+1,iY-1)];
      Gh= S[Give_i(iX+1,iY+1)] + 2*S[Give_i(iX+1,iY)] + S[Give_i(iX-1,iY-1)] - S[Give_i(iX+1,iY-1)] - 2*S[Give_i(iX-1,iY)] - S[Give_i(iX-1,iY-1)];
      G = sqrt(Gh*Gh + Gv*Gv);
      i= Give_i(iX,iY); /* compute index of 1D array from indices of 2D array */
      if (G==0) {D[i]=255;} /* background */
      else {D[i]=0;}  /* boundary */
    }
  }
 
   
 
  return 0;
}



// copy from Source to Destination
int CopyBoundaries(unsigned char S[],  unsigned char D[])
{
 
  unsigned int iX,iY; /* indices of 2D virtual array (image) = integer coordinate */
  unsigned int i; /* index of 1D array  */
 
 
  //printf("copy boundaries from S array to D array \n");
  for(iY=1;iY<iyMax-1;++iY)
    for(iX=1;iX<ixMax-1;++iX)
      {i= Give_i(iX,iY); if (S[i]==0) D[i]=0;}
 
 
 
  return 0;
}

















// *******************************************************************************************
// ********************************** save A array to pgm file ****************************
// *********************************************************************************************

int
SaveArray2PGMFile (unsigned char A[],  char * n, char *comment)
{

  FILE *fp;
  const unsigned int MaxColorComponentValue = 255;	/* color component is coded from 0 to 255 ;  it is 8 bit color file */
  char name[100];		/* name of file */
  snprintf (name, sizeof name, "%s", n );	/*  */
  char *filename = strcat (name, ".pgm");
  char long_comment[200];
  sprintf (long_comment, "fc(z)=z^3+c  %s", comment);





  // save image array to the pgm file 
  fp = fopen (filename, "wb");	// create new file,give it a name and open it in binary mode 
  fprintf (fp, "P5\n # %s\n %u %u\n %u\n", long_comment, iWidth, iHeight, MaxColorComponentValue);	// write header to the file
  size_t rSize = fwrite (A, sizeof(A[0]), iSize, fp);	// write whole array with image data bytes to the file in one step 
  fclose (fp);

  // info 
  if ( rSize == iSize) 
  	{
  		printf ("File %s saved ", filename);
  		if (long_comment == NULL || strlen (long_comment) == 0)
    		printf ("\n");
  			else { printf (". Comment = %s \n", long_comment); }
  	}
  	else {printf("wrote %zu elements out of %llu requested\n", rSize,  iSize);}

  return 0;
}




int
PrintCInfo ()
{

  printf ("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);	// https://stackoverflow.com/questions/20389193/how-do-i-check-my-gcc-c-compiler-version-for-my-eclipse
  // OpenMP version is displayed in the console : export  OMP_DISPLAY_ENV="TRUE"

  printf ("__STDC__ = %d\n", __STDC__);
  printf ("__STDC_VERSION__ = %ld\n", __STDC_VERSION__);
  printf ("c dialect = ");
  switch (__STDC_VERSION__)
    {				// the format YYYYMM 
    case 199409L:
      printf ("C94\n");
      break;
    case 199901L:
      printf ("C99\n");
      break;
    case 201112L:
      printf ("C11\n");
      break;
    case 201710L:
      printf ("C18\n");
      break;
      //default : /* Optional */

    }

  return 0;
}


int
PrintProgramInfo ()
{


  // display info messages
  printf ("Numerical approximation of Julia set for F(z,C) =  z^3 + c) \n");
  printf ("parameter C = ( %.16f ; %.16f ) \n", creal (C), cimag (C));
  printf ("Period  = %d  orbit : \n", period);
  printf ("\tparameter z2a = ( %.16f ; %.16f ) \n", creal (z2a), cimag (z2a));
  printf ("\tparameter z2b = ( %.16f ; %.16f ) \n", creal (z2b), cimag (z2b));
  
  

  printf ("Image Width = %f in world coordinate\n", ZxMax - ZxMin);
  printf ("PixelWidth = %.16f \n", PixelWidth);
  printf ("AR = %.16f = %f *PixelWidth = %f %% of ImageWidth \n", AR, AR / PixelWidth, AR / ZxMax - ZxMin);


  printf("pixel counters\n");
  printf ("\tuUnknown = %llu\n", uUnknown);
  printf ("\tuExterior = %llu\n", uExterior);
  printf ("\tuInterior = %llu\n", uInterior);
  printf ("Sum of pixels  = %llu\n", uInterior+uExterior + uUnknown);
  printf ("all pixels of the array = iSize = %llu\n", iSize);


  // image corners in world coordinate
  // center and radius
  // center and zoom
  // GradientRepetition
  printf ("Maximal number of iterations = iterMax = %d \n", IterMax);
  printf ("ratio of image  = %f ; it should be 1.000 ...\n", ratio);
  //




  return 0;
}



int SetPlane(complex double center, double radius, double a_ratio){

  ZxMin = creal(center) - radius*a_ratio;	
  ZxMax = creal(center) + radius*a_ratio;	//0.75;
  ZyMin = cimag(center) - radius;	// inv
  ZyMax = cimag(center) + radius;	//0.7;
  return 0;

}


// *****************************************************************************
//;;;;;;;;;;;;;;;;;;;;;;  setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// **************************************************************************************

int
setup ()
{

  fprintf (stderr, "setup start\n");






  /* 2D array ranges */

  iWidth = iHeight* DisplayAspectRatio ;
  iSize = iWidth * iHeight;	// size = number of points in array 
  // iy
  iyMax = iHeight - 1;		// Indexes of array starts from 0 not 1 so the highest elements of an array is = array_name[size-1].
  //ix

  ixMax = iWidth - 1;

  /* 1D array ranges */
  // i1Dsize = i2Dsize; // 1D array with the same size as 2D array
  iMax = iSize - 1;		// Indexes of array starts from 0 not 1 so the highest elements of an array is = array_name[size-1].


  SetPlane( center, radius,  DisplayAspectRatio );	
  /* Pixel sizes */
  PixelWidth = (ZxMax - ZxMin) / ixMax;	//  ixMax = (iWidth-1)  step between pixels in world coordinate 
  PixelHeight = (ZyMax - ZyMin) / iyMax;
  ratio = ((ZxMax - ZxMin) / (ZyMax - ZyMin)) / ((double) iWidth / (double) iHeight);	// it should be 1.000 ...

  ER = 2.0; // 
  ER2 = ER*ER;
  AR_max = 5*PixelWidth*iWidth/2000.0 ; // adjust first number 
  // GiveTunedAR(const int i_Max, const complex double zcr, const double c, const double zp){
  AR = GiveTunedAR(200, C, AR_max);
  AR2 = AR * AR;
  //AR12 = AR/2.0;
  
  
    



  /* create dynamic 1D arrays for colors ( shades of gray ) */
  data = malloc (iSize * sizeof (unsigned char));

  edge = malloc (iSize * sizeof (unsigned char));
  if (data == NULL || edge == NULL)
    {
      fprintf (stderr, " Could not allocate memory");
      return 1;
    }





 


  fprintf (stderr, " end of setup \n");

  return 0;

}				// ;;;;;;;;;;;;;;;;;;;;;;;;; end of the setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




int
end ()
{


  fprintf (stderr, " allways free memory (deallocate )  to avoid memory leaks \n");	// https://en.wikipedia.org/wiki/C_dynamic_memory_allocation
  free (data);
  free(edge);


  PrintProgramInfo ();
  PrintCInfo ();
  return 0;

}

// ********************************************************************************************************************
/* -----------------------------------------  main   -------------------------------------------------------------*/
// ********************************************************************************************************************

int
main ()
{
  setup ();

  Test();
  
  DrawImage (data, Fatou);	// first find Fatou
  SaveArray2PGMFile (data,  "Fatou" , "Fatou ");
  
  
  ComputeBoundaries(data,edge);
  SaveArray2PGMFile (edge, "Fatou_b", "Boundaries of Fatou"); 
  
  CopyBoundaries(edge,data);
  SaveArray2PGMFile (data,  "FatouAnd B", "Fatou with boundaries"); 
  
  
  DrawImage (data, LSM);	// first find Fatou
  SaveArray2PGMFile (data,  "LSM_9", "LSM");
  
  
  ComputeBoundaries(data,edge);
  SaveArray2PGMFile (edge, "LCM_9", "Level Curves Method = Boundaries of Level Sets"); 
  
  DrawForwardOrbit(zcr, 100, edge);
  SaveArray2PGMFile (edge, "LCM_cr", "LCM and critical orbit");  
  
  
  MarkTraps(data);
  MarkAttractors(data);
  SaveArray2PGMFile (data, "LSM_a", "Fatou with boundaries and traps; name = iWidth_IterMax_n"); 
  
  
  /*
  ComputeBoundaries(data,edge);
  SaveArray2PGMFile (edge, 1, "Boundaries of Fatou; name = iWidth_IterMax_n"); 
  
  CopyBoundaries(edge,data);
  SaveArray2PGMFile (data,  2, "Fatou with boundaries; name = iWidth_IterMax_n"); 
  
  
  	
  DrawFatouImageLSM (data, IterMax);	// first find Fatou
  SaveArray2PGMFile (data, 6, "Fatou LSM, name = iWidth_IterMax_n");
  
 
  
  CopyBoundaries(edge,data);
  SaveArray2PGMFile (data, 8, "LSM with boundaries; name = iWidth_IterMax_n"); 
  */
  
  end ();

  return 0;
}

bash source code

[edit]
#!/bin/bash 
 
# script file for BASH 
# which bash
# save this file as d.sh
# chmod +x d.sh
# ./d.sh
# checked in https://www.shellcheck.net/




printf "make pgm files \n"
gcc d.c -lm -Wall -march=native -fopenmp

if [ $? -ne 0 ]
then
    echo ERROR: compilation failed !!!!!!
    exit 1
fi


export  OMP_DISPLAY_ENV="TRUE"
printf "display OMP info \n"

time ./a.out > a.txt

export  OMP_DISPLAY_ENV="FALSE"

printf "convert all pgm files to png using Image Magic convert \n"
# for all pgm files in this directory
for file in *.pgm ; do
  # b is name of file without extension
  b=$(basename "$file" .pgm)
  # convert  using ImageMagic
  convert "${b}".pgm -resize 2000x2000 "${b}".png
  echo "$file"
done


printf "delete all pgm files \n"
rm ./*.pgm

 
echo OK
# end

Makefile

[edit]
all: 
	chmod +x d.sh
	./d.sh

File history

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

Date/TimeThumbnailDimensionsUserComment
current19:43, 22 May 2021Thumbnail for version as of 19:43, 22 May 20212,000 × 2,000 (732 KB)Soul windsurfer (talk | contribs)level curves cross at critical point
13:54, 6 January 2021Thumbnail for version as of 13:54, 6 January 20212,000 × 2,000 (758 KB)Soul windsurfer (talk | contribs)better position of set
05:48, 6 January 2021Thumbnail for version as of 05:48, 6 January 20212,000 × 2,000 (568 KB)Soul windsurfer (talk | contribs)Uploaded own work with UploadWizard

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file:

Metadata