This is a file from the Wikimedia Commons

File:Fatou sets for Blaschke fraction f(z) = rho * z^2 * (z-3) over (1-3z) with LCM and critical orbit.png

From Wikibooks, open books for an open world
Jump to navigation Jump to search

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

Summary

Description
English: Fatou sets for Blaschke fraction f(z) = rho * z^2 * (z-3) over (1-3z) with LCM and critical orbit. Parameter rho = -0.6172665900123702 +0.7867540637673888*I turn(rho) =0.3558800000000000 radius(rho) = 1.0 is a cusp point. Rho is a modulus one complex number chosen so that there is on the unit circle a parabolic period 3 cycle. The location and original image by Arnaud Chéritat. Parabolic critical point, it's orbit ( critical orbit) and parabolic period 3 cycle is shown. There are 3 Fatou components:
  • basin of attraction to infinity ( superattracting)
  • basin of attraction to fixed point z=0 ( superattracting) with critical point z=0
  • basin of parabolic period 3 cycle ( critical point z= 1)
Date
Source Own work with help of experts from FF
Author Adam majewski
Other versions

Licensing

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.


c source code

/*

  -------------------
  Near Parabolic Renormalization for Unicritical Holomorphic Maps by Arnaud Chéritat
  http://amj.math.stonybrook.edu/pdf-Springer-final/020-0172.pdf
  https://fractalforums.org/noobs-corner/76/can-you-identify-this-fractal/4776/new#new
  https://math.stackexchange.com/questions/4472496/how-can-i-find-parameter-of-the-rational-map

 

  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 ========================
  
  DrawImageOf -> DrawPointOf -> ComputeColorOf ( FunctionTypeT FunctionType , complex double z) -> ComputeColor
  
  
  check only last function  which computes color of one pixel for given Function Type
  
  






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

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



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


  gcc d.c -lm -Wall -Wextra -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 ------------------------------------------------------------ */

// 

static unsigned int iHeight = 8000;	//  size of image  in pixels = iHeight* DisplayAspectRatio * iWidth
double  DisplayAspectRatio  = 1.5; //  iWidth = iHeight* DisplayAspectRatio ;  https://en.wikipedia.org/wiki/Aspect_ratio_(image)

// virtual 2D array and integer ( screen) coordinate
// Indexes of array starts from 0 not 1 





static int ixMin = 0;	// Indexes of array starts from 0 not 1
static int ixMax;	//
static int iWidth;	// horizontal dimension of array :  iWidth = iHeight* DisplayAspectRatio ;

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


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





// rgb array = 24bit color = 3 bytes
const int iColorSize = 3 ; // RGB = 3*(unsigned char)
long long  int iSize_rgb; // number of elements in rgb array
unsigned char *rgbData; // for ppm file


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

// unsigned int i; // var = index of 1D array
//static unsigned int iMin = 0; // Indexes of array starts from 0 not 1
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 = 3.1; 
complex double plane_center = 1.5 ;

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; 

complex double trap_center; // for parabolic basin
double ER; // EscapeRadius
double ER2;			//= 1e60;
double AR; // AttractingRadius ; bigger values do not works
double AR2;


/* 
FunctionType = representing functions
BD = Binary decomposition
MBD  = Modified BD is better, so BD is not used


*/


typedef enum  {
FatouBasins = 0, FatouComponents = 2,  LSM = 3, LSM2 = 4, Unknown = 5 , BD = 6, MBD = 7 , SAC = 8, DLD = 9, ND = 10 , 
NP= 11, POT = 12 , Blend = 13, DEM = 14, IBD = 15, ParabolicCheckerboard = 16
		
} FunctionTypeT; 
// FunctionTypeT FunctionType;





int IterMax = 1000000;
int IterMax_LSM = 1000000;
//int IterMax_DEM = 10000000;

/* colors = shades of gray from 0 to 255 

   unsigned char colorArray[2][2]={{255,231},    {123,99}};
   color = 245;  exterior 
   
   here are two period 2 basins: basin1  and basin2
   each basin is a basin of attraction of period 2 cycle
   
   Each cycle has immediate basin of attraction which consist of 2 components ( and it's preimages)
   so we need 4 colors 
   
   also exterior is a component oof one basin , 
   it is not a basin of attraction to infiiniity
   
   
   
   
   
*/
const unsigned char iColorOfBasin1 = 255;
const unsigned char iColorOfBasin2 = 195;
unsigned char iColorOfBasin3 = 135;
unsigned char iColorOfInterior = 200;
unsigned char iColorOfInterior1 = 200;
unsigned char iColorOfInterior2 = 250;

unsigned char iColorOfExterior = 150;

// for parabolic chessboards
unsigned char colorArray[2][2]={{255,231},
				   {123,99}}; /* shades of gray used in image */

unsigned char iColorOfBoundary = 0;
unsigned char iColorOfUnknown = 5;





// pixel counters
long long int iUnknown = 0;

long long int iInterior = 0;
long long int iExterior = 0;



/* critical points */
complex double zcr1 = 0.0; // superattracting
complex double zcr2 = 1.0; // parabolic





// 
const int period = 3;
complex double zp0;  // parabolic period 3 point


/*



*/

complex double rho; //

// for MBD
static double TwoPi=2.0*M_PI; // texture

// see Adrien Douady _ La dynamique du lapin (1996)  https://www.youtube.com/watch?v=JttLtB0Gkdk&t=894s


// update with f function 
const char *f_description = "Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z)"; // without /n !!!



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






// It is fig 3 from paper : Near Parabolic Renormalization for Unicritical Holomorphic Maps by Arnaud Chéritat	
// http://amj.math.stonybrook.edu/pdf-Springer-final/020-0172.pdf
// z -> rho * z^2 * (z-3)/(1-3z)
// complex function the Blaschke fraction
// rho coefficient is used as a global variable
// update with f_decription string
complex double f(const complex double z0) {

  complex double z; 
  z = rho*z0*z0*(z0-3.0)/(1.0-3.0*z0);
  return  z;
}
	
double c_arg(complex double z)
{
 double arg;
 arg = carg(z);
 if (arg<0.0) arg+= TwoPi ; 
 return arg; 
}

double c_turn(complex double z)
{
 double arg;
 arg = c_arg(z);
 return arg/TwoPi; 
}





int is_z_outside(complex double z){

  if (creal(z) >ZxMax ||
      creal(z) <ZxMin ||
      cimag(z) >ZyMax ||
      cimag(z) <ZyMin)
    {return 1; } // is outside = true
      
    
  return 0; // is inside = false



}









// 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;




}







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

double cabs2(complex double z){

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


}






/* -----------  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;
}





complex double GivePeriodicPoint(const complex double zcr, const int iMax){

	
	complex double z = zcr;
	 for (int i=0; i< iMax; ++i ){
		z = f(z); // forward iteration
   		
   		}
   	//fprintf(stdout, "zp =  %.16f %+.16f*i \n", creal (z), cimag (z));
   	
   	
   	return z;

}







/* 
   How to choose size of attracting trap

petal in the parabolic case : radius of a circle with parabolic point on it's boundary
radius of the circle with attractor as a center
such that level curves cross at critical point ?


   is it possible to adjust AR so that level curves in interior have figure 8?

   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 zp0 and Julia set
   * if critical point is attracted by another cycye ( then change periodic point zp0)

   Made with help of Claude Heiland-Allen


   attracting radius of circle around finite attractor
   there are 2 basins so  
  
  
   It would have to be done separately in each basin.

   A suggested method:

   For each critical point, forward iterate to find an attractor and then thin out the critical point set to only one per basin by removing all but one that converge to a common attractor, for each attractor.
   For each pixel, calculate a smoothed iteration value (e.g. using the methods in my GVC coloring ucl) and note which basin it is in.
   For each critical point in the reduced set, calculate a smoothed iteration value using the same method as in step 2.
   For each pixel, subtract from its smoothed iteration value the one found in step 3 for the critical point that shares its basin. Note that the critical point itself, if inside the image rectangle and in a pixel center, will end up with zero and some points may end up with negative values.
   The level set boundaries you want will now be the boundaries where the sign or the integer part of the modified smoothed iteration value changes. In particular, the -0.something to +0.something transition will pass through the critical point, the n.something to (n+1).something transitions for nonnegative n will pass through its images, and the same for negative n will pass through its preimages.

   pauldebrot 
   https://fractalforums.org/programming/11/crtical-points-and-level-curves/4323/msg29514#new
  


*/
double GiveTunedAR( const complex double zcr, const complex double zf, const int iter_Max, const int period){

  
  complex double z = zcr; // initial point z0 = criical point 
  
  
  
  // iterate critical point
  for (int iter=0; iter< iter_Max; ++iter ){
	  
    
    
	for (int p =0; p< period; ++p )	
    		{z = f(z);} // forward iteration
   
  	
  }
  // check distance between zn = f^n(zcr) and periodic point zp0
  
 
  
  double r = cabs(z - zf)/2.0; // zp0 
  // use it as a AR
  return r;
	
	
}

/*

find AR  and center of parabolic trap ( sepal) by simply iteration of critical point 
uses global var AR and 
*/
int  GiveTunedAR_andTrapCenter(const complex double zcr, const complex double zf, const int iter_Max, const int period){

  
  complex double z = zcr; // initial point z0 = criical point 
  
  
  
  // iterate critical point
  for (int iter=0; iter< iter_Max; ++iter ){
	  
    
    
		
    for (int p =0; p< period; ++p )	
    		{z = f(z);} // forward iteration
    
  	
  }
  // check distance between zn = f^n(zcr) and periodic point zp0
  
 
  //fprintf(stdout, "critical point zn =  %.16f %+.16f*I \n", creal (z), cimag (z));
  AR = cabs(z - zf)/2.0; // !!!! 
  trap_center =  (creal(z) + creal(zf))/2.0 + I*(cimag(zf) + cimag(z))/2.0; // midpoint between zf and z
  
  return 0;
	
	
}




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


// ???????

int IsInsideTraps(int ix, int iy){


  complex double z = GiveZ(ix, iy);
  if (  cabs2(trap_center -z) < AR2  || cabs2(z) < AR2)
    {return 1;}
  return 0;



}







/*
  1 basin  = not works here, because whole plane / sphere/ rectanlge is the same , the only one basin
  - unknown ( possibly empty set ) 

*/

unsigned char ComputeColorOfFatouBasins (complex double z)
{



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


		
    	
       if ( cabs2(z) > ER2 ){ return iColorOfBasin1;} // 
      //  
      if ( cabs2(z) < AR2 ){ return iColorOfBasin2;} // basin of zf = 0 
      
      if ( cabs2(trap_center-z) < AR2 ){ return iColorOfBasin3;} // parabolic period 3 basin
		 
      			
     
      z = f(z);		//  iteration: z(n+1) = f(zn)
	

    }


// extra tests does not work 



  iUnknown +=1;
  return iColorOfUnknown;


}


/*
 

*/

unsigned char ComputeColorOfFatouComponents (complex double z)
{



	
	
  


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


     
       if ( cabs2(z) > ER2 ){ return iColorOfExterior;} // defined in the unit disc
	
  
      
     
	 
	if ( cabs2(z) < AR2 ){ return iColorOfInterior1;} // basin of zf = 0 	
	
	 if ( cabs2(trap_center-z) < AR2 ){ return iColorOfInterior2 - (i % period)*7;}	
     
      z = f(z);		//  iteration: z(n+1) = f(zn)
	

    }

  
  return iColorOfUnknown;


}




/*
attracting petals ( gray curves)
take 2 points: last point of critical orbit and fixed point.
draw circle which is passing thru above 2 points and with diameter equal to distance between such 2 points. Such circle is the smallest ( here not in general) attracting petal




*/

unsigned char ComputeColorOfLSM (complex double z)
{



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


		
       if ( cabs2(z) > ER2 ){ return (7 * i) % 255;} 
       
       
       if ( cabs2(z) < AR2 ){ return (9*i) % 255;} // basin of 0
	
       
       if ( cabs2(trap_center-z) < AR2 )
		 
       		{ return (16*i) % 255;} // cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
	 
     
	
      z = f(z);	

    }

  return iColorOfUnknown;


}

/*
LSM only uin parabolic basin 

*/

unsigned char ComputeColorOfLSM2 (complex double z)
{

 


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


	
      if ( cabs2(z) > ER2 ) { return iColorOfBasin1;} // 
      if ( cabs2(z) < AR2 ) { return iColorOfBasin2;}
     
       if (   ( cabs2(trap_center-z) < AR2 ))
       		{ return (16*i) % 255;} // cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
	 
     
	
      z = f(z);	

    }

  return iColorOfUnknown;


}


unsigned char ComputeColorOfBD (complex double z)
{



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


       if ( cabs2(z) > ER2 ) // basin of infinity
       	{ if (cimag(z) < 0) // binary decomposition of target set
       				{  return 1;}
       				else {return 250; }} // 
	
      if ( cabs2(z) < AR2 )// basin of 0
      		{ 
       			if (cimag(z) > 0) // binary decomposition of target set
       				{  return 2;}
       				else {return 251; }
      	}
      
       if ( cabs2(trap_center-z) < AR2  )  // basin of 1 = parabolic case with period 3 
       	{
       			if (cabs2(z)>1.0) // binary decomposition of target set
       				{  return 3;}
       				else {return 252; }
       			}
     z = f(z);	
      
      		}
	 
     
	
      

    

  return iColorOfUnknown;


}






// Modified BD : only parabolic basin
unsigned char ComputeColorOfMBD (complex double z)
{



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


	
	cabs2z = cabs2(z);	

     	
      if ( cabs2z > ER2 ) { return iColorOfBasin1;} // 
      if ( cabs2z < AR2 ) { return iColorOfBasin2;}
      		
      if ( cabs2(trap_center-z) < AR2  )  // basin of 1 = parabolic case with period 3 
       	{
       			if (cabs2(z)>1.0) // binary decomposition of target set
       				{  return 3;}
       				else {return 252; }
       			}
	
      z = f(z);	

    }

  return iColorOfUnknown;


}






 



// 
unsigned char ComputeColorOfParabolicCheckerboard (complex double z){

	double cabs2zAR;
  
  	int m;
  	int n;

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

		cabs2zAR = cabs2(trap_center - z);	

		if ( cabs(z) > ER  ) // 
       			{ return iColorOfExterior;}
      		
      		if ( cabs2zAR  < AR2 ){ // if z is inside target set ( orbit trap) = interior of cirlce with radius AR
      			
      			m = (cimag(z) > 0 ? 0 : 1); // petal part
   			n = (i % 2); // attraction time 
   			return colorArray[m][n]; //iColor
     		}
	 
     
	
     		z = f(z);	
    	}

	return iColorOfUnknown;

}




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

	unsigned char iColor;
	
	switch(FunctionType){
  
  		case FatouBasins :{iColor = ComputeColorOfFatouBasins(z); break;}
  	
  		case FatouComponents :{iColor = ComputeColorOfFatouComponents(z); break;}
  
 		case LSM :{iColor = ComputeColorOfLSM(z); break;}
  
  		case LSM2 : {iColor = ComputeColorOfLSM2(z); break;  }	
  
  
  		// case DEM : {iColor = ComputeColorOfDEMJ(z); break;}
	
   	
  		//case Unknown : {iColor = ComputeColorOfUnknown(z); break;}
		
  		case BD : {iColor = ComputeColorOfBD(z); break;}
		
  		case MBD : {iColor = ComputeColorOfMBD(z); break;}
  		
  		
  	
  		//case IBD : {iColor = ComputeColorOfIBD(z); break;}
  	
  		//case ParabolicCheckerboard: {iColor = ComputeColorOfParabolicCheckerboard (z); break;}
  	
  		//case ParabolicCheckerboard2: {iColor = ComputeColorOfParabolicCheckerboard2 (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 */
  if(i<0 && i> iMax)
    { return 1;}
  
  z = GiveZ(ix,iy);
  iColor = ComputeColor(FunctionType, z);
  A[i] = iColor ;		// 
  		
  	  
  return 0;
}




int DrawImage ( unsigned char A[], FunctionTypeT FunctionType){

  int ix, iy;		// pixel coordinate 

  fprintf (stderr, "compute image %d \n", FunctionType);
  // for all pixels of image 
#pragma omp parallel for schedule(dynamic) private(ix,iy) shared(A, ixMax , iyMax, iUnknown, iInterior, iExterior)
  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);	//  
    }
  fprintf (stderr, "\n");	//info 
  return 0;
}




// plots raster point (ix,iy) 
int DrawPoint_8and24 ( unsigned char A8[], unsigned char A24[], FunctionTypeT FunctionType, int ix, int iy){


  int i;			/* index of 1D array */
  int i24; // = i*iColorSize; // compute index of F array
  unsigned char iColor;
  complex double z;


  i = Give_i (ix, iy);		/* compute index of 1D array from indices of 2D array */
  if(i<0 && i> iMax)
    { return 1;}
  
  z = GiveZ(ix,iy);
  iColor = ComputeColor(FunctionType, z);
  A8[i] = iColor ;
  
  /*  
     from ComputeColorOfMBD
     iColorOfBasin1
     iColorOfBasin2
     basin3 : 3 or 252
      */ 
      
      
    i24 = i*iColorSize; // compute index of rgb array  
    
    
  switch( iColor ) //  do not repeat computations , check color of gray array
{
	
	case 3:
			A24[i24]   =   0;
			A24[i24+1] =  64;
			A24[i24+2] = 255; // A Cheritat blue
			break;
			
	case 252:
			A24[i24]   = 240  ;
			A24[i24+1] = 220;
			A24[i24+2] =   0; // A Cheritat yellow
			break;
			
	default:	A24[i24]   = 255;
			A24[i24+1] = 255;
			A24[i24+2] = 255; // 
	
}    
  		
  	  
  return 0;
}




int DrawImage_8and24 ( unsigned char A8[], unsigned char A24[], FunctionTypeT FunctionType){

  int ix, iy;		// pixel coordinate 

  fprintf (stderr, "compute image %d \n", FunctionType);
  // for all pixels of image 
#pragma omp parallel for schedule(dynamic) private(ix,iy) shared(A8, A24, ixMax , iyMax, iUnknown, iInterior, iExterior)
  for (iy = iyMin; iy <= iyMax; ++iy)
    {
      fprintf (stderr, " %d from %d \r", iy, iyMax);	//info 
      for (ix = ixMin; ix <= ixMax; ++ix)
	DrawPoint_8and24(A8, A24, FunctionType, ix, iy);	//  
    }
  fprintf (stderr, "\n");	//info 
  return 0;
}





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

	
  int ix = (creal(z)-ZxMin)/PixelWidth;
  int iy = (ZyMax - cimag(z))/PixelHeight;
  int i = Give_i(ix,iy); /* index of _data array */
	
  	
	
  if(i>-1 && i< iMax)
    {A[i]= 0; // 255-A[i];
    }
	
	
  return 0;
	
}






int IsInsideCircle (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;
	  

} 

// Big point = disk 
int PlotBigPointInv(const complex double z, const double p_size, unsigned char A[]){

	
  int ix_seed = (creal(z)-ZxMin)/PixelWidth;
  int iy_seed = (ZyMax - cimag(z))/PixelHeight;
  int i;
	
	
  if (  is_z_outside(z)) 
    {fprintf (stdout,"PlotBigPoint :  z= %.16f %+.16f*I is outside\n", creal(z), cimag(z)); return 1;} // do not plot	
	
  /* mark seed point by big pixel */
  int iSide =p_size ; /* 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 (IsInsideCircle(iX, iY, ix_seed, iy_seed, iSide)) {
	i= Give_i(iX,iY); /* index of _data array */
	//if(i>-1 && i< iMax)
	unsigned char colorA = A[i];
	if ( colorA < 170 && colorA > 140) 
		{colorA = 0; }
		else {colorA = 255 - colorA;} 
	A[i] = colorA;
      }
      // else {printf(" bad point \n");}
	
    }}
	
	
  return 0;
	
}

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

	
  int ix_seed = (creal(z)-ZxMin)/PixelWidth;
  int iy_seed = (ZyMax - cimag(z))/PixelHeight;
  int i;
	
	
  if (  is_z_outside(z)) 
    {fprintf (stdout,"PlotBigPoint :  z= %.16f %+.16f*I is outside\n", creal(z), cimag(z)); return 1;} // do not plot	
	
  /* mark seed point by big pixel */
  int iSide =p_size*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 (IsInsideCircle(iX, iY, ix_seed, iy_seed, iSide)) {
	i= Give_i(iX,iY); /* index of _data array */
	//if(i>-1 && i< iMax)
	A[i] = iColor;
      }
      // else {printf(" bad point \n");}
	
    }}
	
	
  return 0;
	
}


int PlotAllPoints(const complex double zz[], int kMax, unsigned char iColor, double p_size,unsigned char A[]){

  int k;
	
	
  //printf("kMax = %d \n",kMax);
	

  for (k = 0; k < kMax; ++k)
    {
      //fprintf(stderr, "z = %+f %+f \n", creal(zz[k]),cimag(zz[k]));
      PlotBigPoint(zz[k], iColor, p_size, A);}
  return 0;

}




int DrawForwardOrbit(const complex double z0, const long long int i_Max,unsigned char iColor, double p_size, unsigned char A[]){
 

  
  long long int i; /* nr of point of critical orbit */
  complex double z = z0;
    fprintf (stderr,"draw forward orbit \n");
 
  PlotBigPoint(z, iColor, p_size, A);
  
  /* forward orbit of critical point  */
  for (i=1;i<i_Max ; ++i)
    {
      z  = f(z);
      //if (cabs2(z - z2a) > 2.0) {return 1;} // escaping
      //if ( (i % period) == 0) {
      PlotBigPoint(z,iColor, p_size/3 , A);
      //} // draw only one part
     }
  
  fprintf (stdout,"first point of the orbit z0= %.16f %+.16f*I \n", creal(z0), cimag(z0));
  fprintf (stdout,"last point of the orbit z= %.16f %+.16f*I \n", creal(z), cimag(z));
   
  return 0;
 
}



// ***********************************************************************************************
// ********************** draw line segment ***************************************
// ***************************************************************************************************




// plots raster point (ix,iy) 
int iDrawPoint( int ix, int iy, unsigned char iColor, unsigned char A[]){ 

  /* i =  Give_i(ix,iy) compute index of 1D array from indices of 2D array */
  if (ix >=ixMin && ix<=ixMax && iy >=iyMin && iy<=iyMax )
    {A[Give_i(ix,iy)] = iColor;}
  else {fprintf (stdout,"iDrawPoint :   (%d; %d) is outside\n", ix,iy); }

  return 0;
}



/*
  http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm
  Instead of swaps in the initialisation use error calculation for both directions x and y simultaneously:
*/
void iDrawLine( int x0, int y0, int x1, int y1, unsigned char iColor, unsigned char A[]) 
{
  int x=x0; int y=y0;
  int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
  int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; 
  int err = (dx>dy ? dx : -dy)/2, e2;

  for(;;){
    iDrawPoint(x, y, iColor, A);
    if (x==x1 && y==y1) break;
    e2 = err;
    if (e2 >-dx) { err -= dy; x += sx; }
    if (e2 < dy) { err += dx; y += sy; }
  }
}




int dDrawLineSegment(double complex Z0, double complex Z1, int color, unsigned char *array){

  double Zx0 = creal(Z0);
  double Zy0 = cimag(Z0);
  double Zx1 = creal(Z1);
  double Zy1 = cimag(Z1);
  int ix0, iy0; // screen coordinate = indices of virtual 2D array 
  int ix1, iy1; // screen coordinate = indices of virtual 2D array

  // first step of clipping
  //if (  Zx0 < ZxMax &&  Zx0 > ZxMin && Zy0 > ZyMin && Zy0 <ZyMax 
  // && Zx1 < ZxMax &&  Zx1 > ZxMin && Zy1 > ZyMin && Zy1 <ZyMax )
   	
  ix0= (Zx0- ZxMin)/PixelWidth; 
  iy0 = (ZyMax - Zy0)/PixelHeight; // inverse Y axis 
  ix1= (Zx1- ZxMin)/PixelWidth; 
  iy1= (ZyMax - Zy1)/PixelHeight; // inverse Y axis 
   	
  // second step of clipping
  if (ix0 >=ixMin && ix0<=ixMax && ix0 >=ixMin && ix0<=ixMax && iy0 >=iyMin && iy0<=iyMax && iy1 >=iyMin && iy1<=iyMax )
    iDrawLine(ix0,iy0,ix1,iy1,color, array) ;

  return 0;
}




int DrawAttractors(const complex double zpp,  double p_size, unsigned char A[]){

	unsigned char color = 0;
	
	
  	complex double z = zpp;
  	complex double zn = f(z);
  	// join points by lin to create closed curve
  	for (int i=0;i<period ; ++i){
  		PlotBigPoint(z, color, p_size, A);
  		dDrawLineSegment(z, zn, color,A);
  		z = zn;
  		zn = f(z);
  		}
  	
  	
  	dDrawLineSegment(zn, zpp, color,A);
  	// 
  	//PlotAllPoints(zpp, period, color, p_size,A);
	
	
	

  return 0;

}




int MarkTraps(unsigned char A[]){

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


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



int MarkTrapsForBD(unsigned char A[]){

  int ix, iy;		// pixel coordinate 
  int i;
  complex double z;


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







// ***********************************************************************************************
// ********************** mark immediate basin of attracting cycle***************************************
// ***************************************************************************************************


int FillContour(complex double seed,  unsigned char color, unsigned char _data[]){ 
  /* 
     fills contour with black border ( color = iColorOfBoundary)  using seed point inside contour 
     and horizontal lines 
     it starts from seed point, saves max right( iXmaxLocal) and max left ( iXminLocal) interior points of horizontal line,
     in new line ( iY+1 or iY-1) it computes new interior point  : iXmidLocal=iXminLocal + (iXmaxLocal-iXminLocal)/2;
     result is stored in _data array : 1D array of 1-bit colors ( shades of gray)
     it does not check if index of _data array is good  so memory error is possible 
     
     it need array with components boundaries mrked by iColorOfBoundary
     
  */
	double dXseed = creal(seed);
	double dYseed = cimag(seed);
	// from 
  	int iXseed = (int)((dXseed - ZxMin)/PixelWidth);
  	int iYseed = (int)((ZyMax - dYseed )/PixelHeight); // reversed Y axis
  	
  	
  	
  	
  	int iX; /* seed integer coordinate */
    	int iY = iYseed;
    	/* most interior point of line iY */
    	int iXmidLocal=iXseed;
    	/* min and max of interior points of horizontal line iY */
    	int iXminLocal;
    	int iXmaxLocal; 
  	int i ; /* index of _data array */;


	//fprintf (stderr, "FillContour seed = %.16f %+.16f = %d %+d\n",creal(seed), cimag(seed), iXseed,iYseed);
  
  	/* ---------  move up --------------- */ 
  do{
    iX=iXmidLocal;
    i =Give_i(iX,iY); /* index of _data array */;
  
    /* move to right */
    while (_data[i] != iColorOfBoundary) 
      { _data[i]=color;
	iX+=1; 
	i=Give_i(iX,iY);  
      }
    iXmaxLocal=iX-1;

    /* move to left */
    iX=iXmidLocal-1; 
    i=Give_i(iX,iY);
    while (_data[i] != iColorOfBoundary) 
      { _data[i]=color;
	iX-=1; 
	i=Give_i(iX,iY); 
      }
    iXminLocal=iX+1; 

    iY+=1; /* move up */
    iXmidLocal=iXminLocal + (iXmaxLocal-iXminLocal)/2; /* new iX inside contour */
    i=Give_i(iXmidLocal,iY); /* index of _data array */;
    if ( _data[i] == iColorOfBoundary)  break; /*  it should not cross the border */
 
  } while  (iY<iyMax); 
  
  
  /* ------  move down ----------------- */
  iXmidLocal=iXseed;
  iY=iYseed-1;
  
  
  do{
    iX=iXmidLocal;
    i =Give_i(iX,iY); /* index of _data array */;
  
    /* move to right */
    while (_data[i] != iColorOfBoundary) /*  */
      { _data[i]=color;
	iX+=1;
	i=Give_i(iX,iY);  
      }
    iXmaxLocal=iX-1;

    /* move to left */
    iX=iXmidLocal-1; 
    i=Give_i(iX,iY);
    while (_data[i] != iColorOfBoundary) /*  */
      { _data[i]=color;
	iX-=1; /* move to right */
	i=Give_i(iX,iY);  
      }
    iXminLocal=iX+1; 
  
    iY-=1; /* move down */
    iXmidLocal=iXminLocal + (iXmaxLocal-iXminLocal)/2; /* new iX inside contour */
    i=Give_i(iXmidLocal,iY); /* index of _data array */;
    if ( _data[i]== iColorOfBoundary)  break; /*  it should not cross the border */
    
  } while  (0<iY); 

	//fprintf (stderr, "FillContour done \n");
  return 0;
}



// needs zpp and period global var
int  MarkImmediateBasin( unsigned char A[]){
	fprintf (stderr, "mark immediate basin of attracting cycle \n");
	
	//printf("  \n");
	unsigned char iColor = 100;
	
	
	if (period==1)
		{ FillContour(zp0, iColor , A);}
	//for (int i=0;i<period ; ++i){
  		// FillContour(zpp[i], iColor , A);
  		 
  		//}
 	return 0;
 	}







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

// from Source to Destination
int ComputeBoundaries(unsigned char S[], unsigned char D[]){
 
  int iX,iY; /* indices of 2D virtual array (image) = integer coordinate */
  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, 255, iSize*sizeof(*D)); // for heap-allocated arrays, where N is the number of elements = FillArrayWithColor(D , iColorOfBasin1);
 
  // 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]=iColorOfBoundary;}  /* boundary */
    }
  }
 
   
 
  return 0;
}



// copy from Source to Destination
int CopyBoundaries(unsigned char S[],  unsigned char D[]){
 
  int iX,iY; /* indices of 2D virtual array (image) = integer coordinate */
  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]==iColorOfBoundary) D[i]=iColorOfBoundary;}
 
 
 
  return 0;
}


// copy from Source to Destination24
int CopyBoundaries_24(unsigned char S[],  unsigned char D24[]){
 
  int iX,iY; /* indices of 2D virtual array (image) = integer coordinate */
  int i; /* index of 1D array  */
   int i24; // = i*iColorSize; // compute index of F 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]==iColorOfBoundary) {
      		i24 = i*iColorSize; // compute index of 24 array
      		D24[i24]=iColorOfBoundary;
      		D24[i24+1]=iColorOfBoundary;
      		D24[i24+2]=iColorOfBoundary;
      		
      		}
      	
      	}
 
 
 
  return 0;
}





int FillAllArrayWithColor(unsigned char color,  unsigned char A[]){
	memset (A, color,  sizeof (unsigned char ) * iSize);
	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);	/* radius and iHeght are global variables */
  char *filename = strcat (name, ".pgm"); // add extension to base name = complete file name 
  char long_comment[400];
  sprintf (long_comment, "%s %s", f_description,comment); // use global var f_description





  // 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 == (long unsigned int) 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 %lld requested\n", rSize,  iSize);}

  return 0;
}



// *******************************************************************************************
// ********************************** save rgb A array to ppm file ****************************
// *********************************************************************************************



int Save_PPM( const unsigned char A[], const char* sName, const char* comment)
{
  
  	FILE * fp;
  
  	char name [100]; /* name of file */
  	snprintf(name, sizeof name, "%s", sName); /*  */
	char *filename =strcat(name,".ppm");
	
	char long_comment[200];
  	sprintf (long_comment, "%s %s", f_description, comment);
  
  
  
  	// save image to the pgm file 
  	fp= fopen(filename,"wb"); // create new file,give it a name and open it in binary mode 
  
  	if (!fp ) { fprintf( stderr, "ERROR saving ( cant open) file %s \n", filename); return 1; }
  	// else
  	fprintf(fp,"P6\n%d %d\n255\n",  iWidth, iHeight);  // write header to the file
  	size_t rSize = fwrite(A, sizeof(A[0]), iSize_rgb,  fp);  // write array with image data bytes to the file in one step 
  	fclose(fp); 
  
  	// info 
  	if ( rSize == (long unsigned int) iSize_rgb) 
  		{
  			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 %lld requested\n", rSize,  iSize_rgb);}
  	
  	
  	
    
	return 0;
}







int PrintCInfo (){

  fprintf (stdout,"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"

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

    }

  return 0;
}


int
PrintProgramInfo (){


 	// display info messages from global variables
  	fprintf (stdout, "%s\n", f_description); // 
  	fprintf(stdout, "parameter rho =  %.16f %+.16f*I \tturn(rho) =%.16f\t radius = %.16f\n", creal (rho), cimag (rho), c_turn(rho), cabs(rho));
  	fprintf (stdout, " \n");
  	fprintf (stdout, "\tnumber of all pixels = %lld \t unknown = %lld = %f of all pixels\n", iSize, iUnknown, ((double) iUnknown)/iSize );
  	fprintf (stdout, " \n");
  	fprintf(stdout, "critical point zcr1 =  %.16f %+.16f*I \n", creal (zcr1), cimag (zcr1));
	fprintf(stdout, "critical point zcr2 =  %.16f %+.16f*I \n", creal (zcr2), cimag (zcr2));
	fprintf(stdout,  "period %d parabolic cycle \n", period);
	fprintf(stdout, "\tzp0 =  %.16f %+.16f*I \tturn(zpo) =%.16f\t radius = %.16f\n", creal (zp0), cimag (zp0), c_turn(zp0), cabs(zp0));
   	complex double z = f(zp0); // forward iteration
   	fprintf(stdout, "\tzp1 =  %.16f %+.16f*I \tturn(zp1) =%.16f\t radius = %.16f\n", creal (z), cimag (z),  c_turn(z), cabs(z));
   	z = f(z); // forward iteration
   	fprintf(stdout, "\tzp2 =  %.16f %+.16f*I \tturn(zp2) =%.16f\t radius = %.16f\n", creal (z), cimag (z),  c_turn(z), cabs(z));
	fprintf (stdout, " \n");	
	fprintf (stdout, "plane description \n");
  	fprintf (stdout, "\tImage Width = %f in world coordinate\n", ZxMax - ZxMin);
  	fprintf (stdout, "\tPixelWidth = %.16f \n", PixelWidth);
  	fprintf (stdout, "\timage center z =  %.16f %+.16f*I  and radius = %.16f \t zoom = %e\n", creal (plane_center), cimag (plane_center), radius, 1.0/radius);
  	// center and radius
  	// center and zoom
  	fprintf (stdout, "\n");
  	fprintf (stdout, "Maximal number of iterations = iterMax = %d \n", IterMax);
  	fprintf (stdout, "ratio of image  = %f ; it should be 1.000 ...\n", ratio);
  	fprintf (stdout, "\n");
   	fprintf (stdout, "sizes of traps around attractors \n");
  	fprintf (stdout, "\tEscaping Radius = ER = %.16f = %f *PixelWidth = %f %% of ImageWidth \n", ER, ER / PixelWidth, ER / (ZxMax - ZxMin));
	fprintf (stdout, "\ttrap center z =  %.16f %+.16f*I  its turn = %.16f\tand radius = %.16f \n", creal (trap_center), cimag (trap_center), c_turn(trap_center),AR);
	fprintf (stdout, "\tAtracting Radius = AR = %.16f = %f *PixelWidth = %f * ImageWidth \n", AR, AR / PixelWidth, AR / (ZxMax - ZxMin));
	fprintf (stdout, " \n");
   	
   	
   	
  		
  	//




  return 0;
}



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

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

}



// Check Orientation of z-plane image : mark first quadrant of complex plane 
// it should be in the upper right position
// uses global var :  ...
int CheckZPlaneOrientation(unsigned char A[] )
{
 
  	double Zx, Zy; //  Z= Zx+ZY*i;
  	int i; /* index of 1D array */
  	int ix, iy;		// pixel coordinate 
	
  	fprintf(stderr, "compute image CheckOrientation\n");
  	// for all pixels of image 
	#pragma omp parallel for schedule(dynamic) private(ix,iy, i, Zx, Zy) shared(A, ixMax , iyMax) 
  	for (iy = iyMin; iy <= iyMax; ++iy){
    		//fprintf (stderr, " %d from %d \r", iy, iyMax);	//info 
    		for (ix = ixMin; ix <= ixMax; ++ix){
      		// from screen to world coordinate 
      		Zy = GiveZy(iy);
      		Zx = GiveZx(ix);
      		i = Give_i(ix, iy); /* compute index of 1D array from indices of 2D array */
      		if (Zx>0 && Zy>0) A[i]=255-A[i];   // check the orientation of Z-plane by marking first quadrant */
    		}
  	}
   
   
  	return 0;
}







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

int setup ()
{

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



	

  /* 2D array ranges */

  iWidth = iHeight* DisplayAspectRatio ;
  iSize = iWidth * iHeight;	// size = number of points in array 
  iSize_rgb = iSize* iColorSize;
  
  
  
  // 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].

  //radius = 0.0245909491947548; 
  //plane_center =  -0.4862419751909346 -0.8738242051822676*I ;//1.5 ;
  SetPlane( plane_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 ...
  
  // parameter of iterated function 
  rho = 0.7867540637673888*I-0.6172665900123702;

  
   // compute fixed point : f^p(zp0) = zp0
 
   IterMax_LSM = 10000*period;
   zp0 = GivePeriodicPoint(zcr2, IterMax*period+1); //choose one point from 3 point-cycle, this which is in the same componnet with critical point !!!! 
  // LSM  
  // Escape Radius ( of circle around infinity 
   ER = 20.0; // 
  ER2 = ER*ER;
  
  
  
  
  
  	/* find AR  and center of parabolic trap ( sepal) by simply iteration of critical point 
	uses global var AR and  
	note that speed of attractio is high, so low number of iterations 
	GiveTunedAR_andTrapCenter(const complex double zcr, const complex double zf, const int iter_Max, const int period){

	*/
 	GiveTunedAR_andTrapCenter( zcr2, zp0, 100, period);
	AR2 = AR * AR;
  
  
  
  
  // DEM
 // BoundaryWidth = 0.5*iWidth/2000.0  ; //  measured in pixels ( when iWidth = 2000) 
  //distanceMax = BoundaryWidth*PixelWidth;



  /* create dynamic 1D arrays for colors:  shades of gray ( = 8 bit) and rgb ( = 24 bit) */
  	data = malloc (iSize * sizeof (unsigned char));
  	edge = malloc (iSize * sizeof (unsigned char));
 	edge2 = malloc (iSize * sizeof (unsigned char));
 	//
 	rgbData =  malloc (iSize_rgb * sizeof (unsigned char));
 	
 	
  if (data == NULL || edge == NULL || edge2 == NULL || rgbData == NULL)
    {
      fprintf (stderr, " Could not allocate memory");
      return 1;
    }
  




 


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

  return 0;

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




int MakeImages( ){

	
	DrawImage (data, LSM);	 
  	SaveArray2PGMFile (data,  "LSM" , "LSM for all basins");
    
    
  	ComputeBoundaries(data,edge);
  	SaveArray2PGMFile (edge,  "LCM" , "LCM for all basins ");
    
  	DrawForwardOrbit(zcr2, 200*period, 0, 1.5 * iHeight/2000.0, edge);
   	SaveArray2PGMFile (edge,  "LCM_cr2" , "LCM for all 3 basins and critical orbit of parabolic basin");
	  	
	
	
	
  	
    	DrawImage (data, FatouBasins);	 
    	SaveArray2PGMFile (data,  "basins" , "Fatou Basins without boundaries");
    	
    	//DrawForwardOrbit(zu, period*IterMax, 0, 10.0 * iHeight/2000.0, data);
   	//SaveArray2PGMFile (data,  "FatouBasins_u" , "FatouBasins_u");
    	
   
    	ComputeBoundaries(data,edge);
    	SaveArray2PGMFile (edge,  "boundaries" , "Fatou Basins only boundaries");
    	
    	
   
   	CopyBoundaries(edge, data);
        SaveArray2PGMFile (data,  "basins_boundaries" , "Fatou Basins and it's boundaries");
        
        
        DrawForwardOrbit(zcr2, 200*period, 0, 1.5 * iHeight/2000.0, data);
   	SaveArray2PGMFile (data,  "basins_boundaries_cr2" , "Fatou Basins and it's boundaries  and critical orbit of parabolic basin");
  
	DrawAttractors(zp0, 2.0 * iHeight/2000.0, data); // mark cycle
	SaveArray2PGMFile (data,  "basins_boundaries_cr2_attr" , "Fatou Basins and it's boundaries, critical orbit of parabolic basin and parabolic cycle");
    	
    	
    	//PlotBigPoint(zcr1, 0,  10.0, data); // first supperattracting period 1 cycle
    	//DrawAttractors(zp0, 10.0 , data); // second cycle
    	//SaveArray2PGMFile (data,  "FatouBasins_att_trick" , "FatouBasins_att");
    	
    	//MarkTraps(data);
    	//SaveArray2PGMFile (data,  "basins_boundaries_trap" , "Fatou Basins and it's boundaries and traps");
  
  	//MarkTrapsForBD(data);
  	//SaveArray2PGMFile (data,  "basins_boundaries_trapBD" , "Fatou Basins and it's boundaries and traps for BD");
  	//int DrawForwardOrbit(const complex double z0, const unsigned long long int i_Max,unsigned char iColor, double p_size, unsigned char A[]){
  	//DrawImage (data, FatouBasins);	 
 	
  	
    
      /*
    
       DrawImage (data, BD);	
 	SaveArray2PGMFile (data,  "BD" , "BD");
 
 	ComputeBoundaries(data,edge);
  	SaveArray2PGMFile (edge,  "BD_LCM" , "BD_LCM ");
  
  
  	CopyBoundaries(edge, data);
  	SaveArray2PGMFile (data,  "BD_LSCM" , "BD_LSCM");
  
  	
    
    	CopyBoundaries(edge, data);
  	SaveArray2PGMFile (data,  "BD_LSM_LSCM" , "BD_LSM_LSCM");
  
  */
  
  
  
  	
  	
  
        DrawImage_8and24 ( data, rgbData, MBD);
        //DrawImage (data, MBD);	
 	SaveArray2PGMFile (data,  "MBD" , "MBD");
 	Save_PPM( rgbData, "MBD24", "MBD24");

 	
 
 	ComputeBoundaries(data,edge2);
  	SaveArray2PGMFile (edge2,  "MBD_LCM" , "MBD_LCM ");
  	
  	
  	
  	FillAllArrayWithColor(255,edge);
	
	DrawImage (data, LSM2);	 
  	SaveArray2PGMFile (data,  "LSM2" , "LSM only for parabolic basin");
    
    
  	ComputeBoundaries(data,edge);
  	SaveArray2PGMFile (edge,  "LCM2" , "LCM only for parabolic basin");
  	
  	
  	CopyBoundaries(edge, edge2);
  	SaveArray2PGMFile (edge2,  "MBD_LCM_LCM2" , "MBD_LCM  andl LCM only for parabolic basin");
  	
  	
  	DrawForwardOrbit(zcr2, 200*period, 0, 1.5 * iHeight/2000.0, edge2);
   	SaveArray2PGMFile (edge2,  "MBD_LCM_LCM2_cr2" , "MBD_LCM  andl LCM only for parabolic basin  and critical orbit of parabolic basin");
  
  	
  	/*
  	CopyBoundaries_24(edge, rgbData);
  	Save_PPM( rgbData, "MBD24_boundaries", "MBD in 24 color and Fatou Basins boundaries"); 
  	
  	CopyBoundaries_24(edge2, rgbData);
  	Save_PPM( rgbData, "MBD24_LCM", "MBD24_LCM"); 
    
  	CopyBoundaries(edge2, data);
  	SaveArray2PGMFile (data,  "MBD_LSCM" , "MBD_LSCM");
  
  	CopyBoundaries(edge2, edge);
  	SaveArray2PGMFile (edge,  "MBD_LSM_LCM" , "BD_LSM_LCM ");
    
    	CopyBoundaries(edge, data);
  	SaveArray2PGMFile (data,  "MBD_LSM_LSCM" , "BD_LSM_LSCM");
  	
  	
  	
  	
  

  
    DrawImage (data, IBD);	
 SaveArray2PGMFile (data,  "IBD" , "IBD");
 
 ComputeBoundaries(data,edge);
  SaveArray2PGMFile (edge,  "IBD_LCM" , "IBD_LCM ");
  
  
  
  
    
  CopyBoundaries(edge, data);
  SaveArray2PGMFile (data,  "IBD_LSCM" , "IBD_LSCM");
  
  CopyBoundaries(edge2, edge);
  SaveArray2PGMFile (edge,  "IBD_LSM_LCM" , "IBD_LSM_LCM ");
    
    CopyBoundaries(edge, data);
  SaveArray2PGMFile (data,  "IBD_LSM_LSCM" , "IBD_LSM_LSCM");
  
  
  */
  
  
  
  
  
  /*  
    
  CopyBoundaries(edge, data);
  SaveArray2PGMFile (data,  "MBD_LSCM" , "MBD_LSCM");
  
  CopyBoundaries(edge2, edge);
  SaveArray2PGMFile (edge,  "MBD_LSM_LCM" , "MBD_LSM_LCM ");
    
    CopyBoundaries(edge, data);
  SaveArray2PGMFile (data,  "MBD_LSM_LSCM" , "MBD_LSM_LSCM");
  
  
  
  
   DrawImage (data, ParabolicCheckerboard);	
 SaveArray2PGMFile (data,  "ParabolicCheckerboard_LSM" , "ParabolicCheckerboard_LSM");
  
 */
  
  
 //MarkImmediateBasin( edge);
  //DrawAttractors(zpp, 10, edge);
  //SaveArray2PGMFile (edge,  "imm" , "imm"); 
 
 
 
 //PlotBigPoint(trap_center, 0, 10.0, data);
 // DrawAttractors(zpp, 10, data);
 //SaveArray2PGMFile (data,  "FatouBasins_LSCM_zp" , "FatouComponents_LSCM_zp");
     
    
    /*
 
  DrawImage (data, LSM);	
 SaveArray2PGMFile (data,  "LSM" , "LSM");
  
 ComputeBoundaries(data,edge2);
  SaveArray2PGMFile (edge2,  "LCM" , "LCM ");
    
  CopyBoundaries(edge2, data);
 SaveArray2PGMFile (data,  "LSCM" , "LSCM");
 
 DrawAttractors(zp0,  10.0, edge2);
 DrawAttractors(zcr1, 10.0, edge2);
  SaveArray2PGMFile (edge2,  "LCM_a" , "LCM_a ");
  
 
 
    
   DrawImage (data, LS2M);	
 SaveArray2PGMFile (data,  "LS2M" , "LS2M");
  
    
  CopyBoundaries(edge2, data);
 SaveArray2PGMFile (data,  "LS2CM" , "LS2CM");
 
 
 //int DrawForwardOrbit(const complex double z0, const unsigned long long int i_Max,unsigned char iColor, double p_size, unsigned char A[]){
 DrawForwardOrbit(zcr2, IterMax, 0, 20.0, data);
     SaveArray2PGMFile (data,  "LS2CM_cr" , "LS2CM_cr");
    
      DrawImage (data, MBD);	
 SaveArray2PGMFile (data,  "MBD" , "MBD");
 
 ComputeBoundaries(data,edge);
  SaveArray2PGMFile (edge,  "MBD_LCM" , "MBD_LCM ");
  
  
  
  
 //ComputeBoundaries(data,edge2);
  //SaveArray2PGMFile (edge2,  "ParabolicCheckerboard_LCM" , "ParabolicCheckerboard_LCM ");
    
  CopyBoundaries(edge2, data);
 SaveArray2PGMFile (data,  "ParabolicCheckerboard_LSCM" , "ParabolicCheckerboard_LSCM");
 
  
   DrawImage (data, ParabolicCheckerboard2);	
 SaveArray2PGMFile (data,  "ParabolicCheckerboard2_LSM" , "ParabolicCheckerboard2_LSM");
 
 
 ComputeBoundaries(data,edge);
  SaveArray2PGMFile (edge,  "ParabolicCheckerboard2_LCM" , "ParabolicCheckerboard2_LCM ");
    
  CopyBoundaries(edge2, data);
 SaveArray2PGMFile (data,  "ParabolicCheckerboard2_LSCM2" , "ParabolicCheckerboard2_LSCM2");
 */
 return 0;


}



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);
 	free(edge2);
 	free( rgbData);
	//
	PrintProgramInfo ();
	PrintCInfo ();
	//
	return 0;

}

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

int main (){
	
	setup ();
  
  	MakeImages();
   
  	end ();

	return 0;
}

bash source code

#!/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 j.c -lm -Wall -march=native -Wextra -fopenmp

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


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

printf "run the compiled program\n"
time ./a.out > j.txt

export  OMP_DISPLAY_ENV="FALSE"

printf "change Image Magic settings\n"
export MAGICK_WIDTH_LIMIT=100MP
export MAGICK_HEIGHT_LIMIT=100MP

printf "convert all pgm files to png using Image Magic v 6 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 : -resize widthxheight || 
  convert "${b}".pgm -resize '25%' "${b}".png  # iWidth = iHeight* DisplayAspectRatio 
  echo "$file"
done


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


printf "convert all ppm files to png using Image Magic v 6 convert \n"
# for all ppm files in this directory
for file in *.ppm ; do
  # b is name of file without extension
  b=$(basename "$file" .ppm)
  # convert  using ImageMagic : -resize widthxheight || 
  convert "${b}".ppm -resize '25%' "${b}".png  # iWidth = iHeight* DisplayAspectRatio 
  echo "$file"
done


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



 
echo OK

printf "info about software \n"
bash --version
make -v
gcc --version
convert -version
convert -list resource
# end


make

all: 
	chmod +x d.sh
	./d.sh


Tu run the program simply

 make


text output

File LSM.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) LSM for all basins 
File LCM.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) LCM for all basins  
first point of the orbit z0= 1.0000000000000000 +0.0000000000000000*I 
last point of the orbit z= -0.4634422983879005 -0.8861270992723926*I 
File LCM_cr2.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) LCM for all 3 basins and critical orbit of parabolic basin 
File basins.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) Fatou Basins without boundaries 
File boundaries.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) Fatou Basins only boundaries 
File basins_boundaries.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) Fatou Basins and it's boundaries 
first point of the orbit z0= 1.0000000000000000 +0.0000000000000000*I 
last point of the orbit z= -0.4634422983879005 -0.8861270992723926*I 
File basins_boundaries_cr2.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) Fatou Basins and it's boundaries  and critical orbit of parabolic basin 
File basins_boundaries_cr2_attr.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) Fatou Basins and it's boundaries, critical orbit of parabolic basin and parabolic cycle 
File MBD.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) MBD 
File MBD24.ppm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) MBD24 
File MBD_LCM.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) MBD_LCM  
File LSM2.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) LSM only for parabolic basin 
File LCM2.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) LCM only for parabolic basin 
File MBD_LCM_LCM2.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) MBD_LCM  andl LCM only for parabolic basin 
first point of the orbit z0= 1.0000000000000000 +0.0000000000000000*I 
last point of the orbit z= -0.4634422983879005 -0.8861270992723926*I 
File MBD_LCM_LCM2_cr2.pgm saved . Comment = Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z) MBD_LCM  andl LCM only for parabolic basin  and critical orbit of parabolic basin 
Numerical approximation of dynamic plane with Julia set for Blaschke fraction f(z) =  rho * z^2 * (z-3)/(1-3z)
parameter rho =  -0.6172665900123702 +0.7867540637673888*I 	turn(rho) =0.3558800000000000	 radius = 1.0000000000000000
 
	number of all pixels = 96000000 	 unknown = 0 = 0.000000 of all pixels
 
critical point zcr1 =  0.0000000000000000 +0.0000000000000000*I 
critical point zcr2 =  1.0000000000000000 +0.0000000000000000*I 
period 3 parabolic cycle 
	zp0 =  0.7721198156000265 +0.6354769786212899*I 	turn(zpo) =0.1095982501749869	 radius = 0.9999999999999312
	zp1 =  -0.7160802718691544 +0.6980179397692637*I 	turn(zp1) =0.3770327818056167	 radius = 0.9999999999999648
	zp2 =  -0.4606340570623679 -0.8875901449848134*I 	turn(zp2) =0.6738110288425769	 radius = 0.9999999999999494
 
plane description 
	Image Width = 9.300000 in world coordinate
	PixelWidth = 0.0007750645887157 
	image center z =  1.5000000000000000 +0.0000000000000000*I  and radius = 3.1000000000000001 	 zoom = 3.225806e-01

Maximal number of iterations = iterMax = 1000000 
ratio of image  = 1.000000 ; it should be 1.000 ...

sizes of traps around attractors 
	Escaping Radius = ER = 20.0000000000000000 = 25804.301075 *PixelWidth = 2.150538 % of ImageWidth 
	trap center z =  0.7756540161011231 +0.6311334968922280*I  its turn = 0.1087070288990683	and radius = 0.0055996791615811 
	Atracting Radius = AR = 0.0055996791615811 = 7.224790 *PixelWidth = 0.000602 * ImageWidth 
 
gcc version: 11.2.0
__STDC__ = 1
__STDC_VERSION__ = 201710
c dialect = C18

references

Captions

Fatou sets for Blaschke fraction f(z) = rho * z^2 * (z-3) over (1-3z) with LCM and critical orbit

Items portrayed in this file

depicts

3 July 2022

File history

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

Date/TimeThumbnailDimensionsUserComment
current16:25, 3 July 2022Thumbnail for version as of 16:25, 3 July 20223,000 × 2,000 (975 KB)Soul windsurferUploaded own work with UploadWizard

Metadata