File:Douady Rabbit Julia set with modified binary decomposition.png
Page contents not supported in other languages.
Tools
General
Sister projects
In other projects
Appearance
Size of this preview: 600 × 600 pixels. Other resolutions: 240 × 240 pixels | 480 × 480 pixels | 768 × 768 pixels | 1,024 × 1,024 pixels | 2,000 × 2,000 pixels.
Original file (2,000 × 2,000 pixels, file size: 639 KB, MIME type: image/png)
This is a file from the Wikimedia Commons. The description on its description page there is shown below. |
Summary
DescriptionDouady Rabbit Julia set with modified binary decomposition.png |
English: Douady Rabbit Julia set with modified binary decomposition. This image is a composition of: binary decomposition ( of both exterior and interio) and boundaries of level seth mathod ( LSM). Binary decomposition of interior is modified.[1] Binary decomposition as anaproximation of spine, external and internal angles/rays |
Date | |
Source | Own work |
Author | Adam majewski |
Other versions |
|
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
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
/*
here are:
* 1 critical point z=0.0
* 1 weakly attracting cycle period 4
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 -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 ------------------------------------------------------------ */
// virtual 2D array and integer ( screen) coordinate
// Indexes of array starts from 0 not 1
//unsigned int ix, iy; // var
static unsigned int iHeight = 5000; //
static unsigned int iyMin = 0; // Indexes of array starts from 0 not 1
static unsigned int iyMax; //
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
// 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 char *edge2;
// unsigned int i; // var = index of 1D array
//static unsigned int iMin = 0; // Indexes of array starts from 0 not 1
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
//FunctionType = representing functions
typedef enum {FatouBasins = 0, FatouComponents = 2, LSM = 3, LSM_m = 4, Unknown = 5 , BD = 6, MBD = 7 , MBD2 = 8, SAC = 9, DLD = 10, ND = 11, NP= 12, POT = 13 , Blend = 14, DEM = 15
} FunctionTypeT;
// FunctionTypeT FunctionType;
// 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;
// dem
double BoundaryWidth ; //= 1.0*iWidth/2000.0 ; // measured in pixels ( when iWidth = 2000)
double distanceMax ; //= BoundaryWidth*PixelWidth;
double ratio;
double ER;
double ER2; //= 1e60;
double AR; // bigger values do not works
double AR2;
int IterMax = 1000;
int IterMax_LSM = 10000000;
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
*/
unsigned char iColorOfBasin1 = 170;
unsigned char iColorOfInterior = 150;
unsigned char iColorOfExterior = 225;
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 point */
const int period = 3;
complex double zcr = 0.0; //
complex double c = -0.122561166876654 +0.744861766619744*I; // Douady rabbit , c is a center of upper period 3 component
// 1 attracting cycle period 3
complex double zp3[3] ;
complex double zp; // one if periodic pointes
// for MBD
static double TwoPi=2.0*M_PI; // texture
double t0 ; // manually tuned t for MBD
// see https://www.youtube.com/watch?v=JttLtB0Gkdk&t=894s
//
// update with f function
const char *f_description = "Numerical approximation of Julia set for f(z)= z^2 + c "; // without /n !!!
/* ------------------------------------------ functions -------------------------------------------------------------*/
/*
*/
// complex function
// upadte f_description also
complex double f(const complex double z0) {
double complex z = z0;
z = z*z + c;
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;
}
/*
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 zp and Julia set
* if critical point is attracted by another cycye ( then change periodic point zp)
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 double iter_Max){
fprintf(stdout, " Tuned AR = \n");
complex double z = zcr; // initial point z0 = criical point
double iter;
double r ;//= 10 * PixelWidth; // initial value
double rMin = 30 * PixelWidth;
// double t;
// iterate critical point
for (iter=0; iter< iter_Max; iter+=1.0 ){
r = cabs(zp - z);
if ( r<rMin) {break;}
z = f(z); // forward iteration
}
// check distance between zn = f^n(zcr) and periodic point zp
// use it as a AR
return r;
}
// ****************** DYNAMICS = trap tests ( target sets) ****************************
// ???????
int IsInsideTrap(int ix, int iy){
complex double z = GiveZ(ix, iy);
if ( 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 i; // number of iteration
for (i = 0; i < IterMax; ++i)
{
// infinity is superattracting here !!!!!
if ( cabs2(z) > ER2 ){ return iColorOfExterior;}
// 1 Attraction basins
if ( cabs2(zp-z) < AR2 ){ return iColorOfInterior;}
z = f(z); // iteration: z(n+1) = f(zn)
}
return iColorOfUnknown;
}
/*
2 basins
- - basin 1
- - basin 2
- unknown ( possibly empty set )
*/
unsigned char ComputeColorOfFatouComponents (complex double z)
{
int i; // number of iteration
for (i = 0; i < IterMax; ++i)
{
// infinity is superattracting here !!!!!
if ( cabs2(z) > ER2 ){ return iColorOfExterior;}
//1 Attraction basins
if ( cabs2(zp-z) < AR2 ){ return iColorOfBasin1 - (i % period)*20;}
z = f(z); // iteration: z(n+1) = f(zn)
}
return iColorOfUnknown;
}
unsigned char ComputeColorOfLSM (complex double z)
{
double cabs2z;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z);
// infinity is superattracting here !!!!!
if ( cabs2z > ER2 || ( cabs2z < AR2 ))
{ return (10*i) % 255;} // cabs2(zp-z) = cabs2(z) because zp = zcr = 0
z = f(z);
}
return iColorOfUnknown;
}
unsigned char ComputeColorOfBD (complex double z)
{
double cabs2z;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z); // numerical speed up : cabs2(zp-z) = cabs2(z) because zp = zcr = 0
//
if ( cabs2z > ER2 || cabs2z < AR2 ) // if z is inside target set ( orbit trap)
{
if (cimag(z) > 0) // binary decomposition of target set
{ return 0;}
else {return 255; }
}
z = f(z);
}
return iColorOfUnknown;
}
// Modified BD
unsigned char ComputeColorOfMBD (complex double z)
{
double cabs2z;
double turn;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z); // numerical speed up : cabs2(zp-z) = cabs2(z) because zp = zcr = 0
// if z is inside target set ( orbit trap) = exterior of circle with radius ER
if ( cabs2z > ER2 ) // exterior
{
if (cimag(z) > 0) // binary decomposition of target set
{ return 0;}
else {return 255; }
}
if ( cabs2z < AR2 ) // if z is inside target set ( orbit trap) = interior of cirlce with radius AR
{
turn = c_turn(z);
if (turn < t0 || turn > t0+0.5) // modified binary decomposition of target set
{ return 0;}
else {return 255; }
}
z = f(z);
}
return iColorOfUnknown;
}
// Modified BD
unsigned char ComputeColorOfMBD2 (complex double z)
{
double cabs2z;
double turn;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z); // numerical speed up : cabs2(zp-z) = cabs2(z) because zp = zcr = 0
// if z is inside target set ( orbit trap) = exterior of circle with radius ER
if ( cabs2z > ER2 || cabs2z < AR2 ) // exterior and interior : if z is inside target set ( orbit trap) = interior of cirlce with radius AR
{
turn = c_turn(z);
if (turn < t0 || turn > t0+0.5) // modified binary decomposition of target set
{ return 0;}
else {return 255; }
}
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 DEM : {iColor = ComputeColorOfDEMJ(z); break;}
//case Unknown : {iColor = ComputeColorOfUnknown(z); break;}
case BD : {iColor = ComputeColorOfBD(z); break;}
case MBD : {iColor = ComputeColorOfMBD(z); break;}
case MBD2 : {iColor = ComputeColorOfMBD2(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)
{
unsigned 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, 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); //
}
fprintf (stderr, "\n"); //info
return 0;
}
int PlotPoint(const 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 */
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 PlotBigPoint(const complex double z, double p_size, unsigned char A[]){
unsigned int ix_seed = (creal(z)-ZxMin)/PixelWidth;
unsigned int iy_seed = (ZyMax - cimag(z))/PixelHeight;
unsigned 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]= 255; ;// -A[i];
}
// else {printf(" bad point \n");}
}}
return 0;
}
int PlotAllPoints(const complex double zz[], int kMax, 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], p_size, A);}
return 0;
}
int DrawForwardOrbit(const complex double z0, const unsigned long long int i_Max, double p_size, unsigned char A[]){
unsigned long long int i; /* nr of point of critical orbit */
complex double z = z0;
printf("draw forward orbit \n");
PlotBigPoint(z, 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
PlotBigPoint(z, p_size/2 , A);
}
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(unsigned int ix, unsigned 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);
unsigned int ix0, iy0; // screen coordinate = indices of virtual 2D array
unsigned 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 zpa[], int kMax, double p_size, unsigned char A[]){
unsigned char color = 0;
// join points by lin to create closed curve
dDrawLineSegment(zp3[0], zp3[1],color,A);
dDrawLineSegment(zp3[1], zp3[2],color,A);
dDrawLineSegment(zp3[2], zp3[0],color,A);
//
PlotAllPoints(zpa, period, p_size,A);
return 0;
}
int MarkTraps(unsigned char A[]){
unsigned int ix, iy; // pixel coordinate
unsigned 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 (IsInsideTrap(ix, iy)) {
i= Give_i(ix,iy); /* index of _data array */
A[i]= 255;// 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;
}
// fill countours of componnets of immediate basin of attraction
// with color
// needs zpp and period global var
// it needs componnets boundaris in A array !!!!
int MarkImmediateBasin( unsigned char A[]){
fprintf (stderr, "mark immediate basin of attracting cycle \n");
//printf(" \n");
unsigned char iColor = 100;
for (int i=0;i<period ; ++i){
FillContour(zp3[i], iColor , A);
}
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, iColorOfBasin1, 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]=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;
}
// FillAllArrayWithColor
//memset (data, 255, sizeof (unsigned char ) * iSize);
// *******************************************************************************************
// ********************************** 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");
char long_comment[200];
sprintf (long_comment, "%s %s", f_description , 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
fprintf (stdout, "%s \n", f_description );
fprintf (stdout, "c = %.16f %+.16f*i \n", creal (c), cimag (c));
fprintf (stdout, "Image Width = %f in world coordinate\n", ZxMax - ZxMin);
fprintf (stdout, "PixelWidth = %.16f \n", PixelWidth);
fprintf (stdout, "plane description \n");
fprintf (stdout, "center c = %.16f %+.16f*i and radius = %.16f \n", creal (center), cimag (center), radius);
// center and radius
// center and zoom
// GradientRepetition
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, "sizes of traps around attractors \n");
fprintf (stdout, "Atracting Radius = AR = %.16f = %f *PixelWidth = %f %% of ImageWidth \n", AR, AR / PixelWidth, AR / ZxMax - ZxMin);
fprintf (stdout, "Escaping Radius = ER = %.16f = %f *PixelWidth = %f %% of ImageWidth \n", ER, ER / PixelWidth, ER / ZxMax - ZxMin);
fprintf(stdout, "periodic points \n");
for (int i=0;i<period ; ++i){
fprintf(stdout, "z = %.16f %+.16f*i \n", creal (zp3[i]), cimag (zp3[i]));
}
//
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;
}
// 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;
unsigned i; /* index of 1D array */
unsigned 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, "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 ...
// LSM
// escape radius ( of circle around infinity
ER = 200.0; //
ER2 = ER*ER;
// printf("compute periodic orbit (3 points) = forward orbit of critical point \n");
zp3[0] = zcr;
zp3[1] = c;
zp3[2] = f(c);
zp = zp3[0]; // manually tuned before zp
AR = 30* PixelWidth ; //GiveTunedAR(IterMax- 300);
AR2 = AR * AR;
// for MBD
t0 = 1.0 / period; // Is it iternal angle from inetrnal adress ???
// 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 ) */
data = malloc (iSize * sizeof (unsigned char));
edge = malloc (iSize * sizeof (unsigned char));
edge2 = malloc (iSize * sizeof (unsigned char));
if (data == NULL || edge == NULL || edge2 == 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);
free(edge2);
PrintProgramInfo ();
PrintCInfo ();
return 0;
}
// ********************************************************************************************************************
/* ----------------------------------------- main -------------------------------------------------------------*/
// ********************************************************************************************************************
int main ()
{
setup ();
DrawImage (data, FatouBasins);
SaveArray2PGMFile (data, "FatouBasins" , "FatouBasins ");
ComputeBoundaries(data,edge);
SaveArray2PGMFile (edge, "FatouBasins_LCM" , "FatouBasins_LCM ");
CopyBoundaries(edge, data);
SaveArray2PGMFile (data, "FatouBasins_LSCM" , "FatouBasins_LSCM");
DrawImage (data, FatouComponents);
SaveArray2PGMFile (data, "FatouComponents" , "FatouComponents ");
ComputeBoundaries(data,edge);
SaveArray2PGMFile (edge, "FatouComponents_LCM" , "FatouComponents_LCM ");
CopyBoundaries(edge, data);
SaveArray2PGMFile (data, "FatouComponents_LSCM" , "FatouComponents_LSCM");
MarkTraps(data);
SaveArray2PGMFile (data, "FatouComponents_LSCM_trap" , "FatouComponents_LSCM_trap");
DrawAttractors(zp3, period, 10, data);
SaveArray2PGMFile (data, "FatouComponents_LSCM_zp" , "FatouComponents_LSCM_zp");
DrawImage (data, FatouBasins);
ComputeBoundaries(data,edge);
MarkImmediateBasin(edge);
SaveArray2PGMFile (edge, "FatouBasins_LCM_immediate" , "FatouBasins_LCM_immediate");
DrawAttractors(zp3, period, 10, edge);
SaveArray2PGMFile (edge, "FatouBasins_LCM_immediate_zp" , "FatouBasins_LCM_immediate_zp");
DrawImage (data, LSM);
SaveArray2PGMFile (data, "LSM" , "LSM");
ComputeBoundaries(data,edge2);
SaveArray2PGMFile (edge2, "LCM" , "LCM ");
CopyBoundaries(edge2, data);
SaveArray2PGMFile (data, "LSCM" , "LSCM");
DrawImage (data, MBD);
SaveArray2PGMFile (data, "MBD" , "MBD");
ComputeBoundaries(data,edge);
SaveArray2PGMFile (edge, "MBD_LCM" , "MBD_LCM ");
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");
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 -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
convert "${b}".pgm -resize 2000x2000 "${b}".png
echo "$file"
done
printf "delete all pgm files \n"
rm ./*.pgm
echo OK
printf "info about software \n"
bash --version
make -v
gcc --version
convert -version
convert -list resource
# end
make
Makefile :
all:
chmod +x j.sh
./j.sh
Tu run the program simply
make
text output
text from j.txt
File FatouBasins.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouBasins File FatouBasins_LCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouBasins_LCM File FatouBasins_LSCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouBasins_LSCM File FatouComponents.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouComponents File FatouComponents_LCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouComponents_LCM File FatouComponents_LSCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouComponents_LSCM File FatouComponents_LSCM_trap.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouComponents_LSCM_trap kMax = 3 File FatouComponents_LSCM_zp.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c FatouComponents_LSCM_zp File BD.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c BD File BD_LCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c BD_LCM File BD_LSCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c BD_LSCM File LSM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c LSM File LCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c LCM File LSCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c LSCM File MBD.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c MBD File MBD_LCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c MBD_LCM File MBD_LSCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c MBD_LSCM File MBD_LSM_LCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c MBD_LSM_LCM File MBD_LSM_LSCM.pgm saved . Comment = Numerical approximation of Julia set for f(z)= z^2 + c MBD_LSM_LSCM Numerical approximation of Julia set for f(z)= z^2 + c c = -0.1225611668766540 +0.7448617666197440*i Image Width = 3.000000 in world coordinate PixelWidth = 0.0030030030030030 plane description center c = 0.0000000000000000 +0.0000000000000000*i and radius = 1.5000000000000000 Maximal number of iterations = iterMax = 1000 ratio of image = 1.000000 ; it should be 1.000 ... sizes of traps around attractors Atracting Radius = AR = 0.0900900900900901 = 30.000000 *PixelWidth = 1.560060 % of ImageWidth Escaping Radius = ER = 200.0000000000000000 = 66600.000000 *PixelWidth = 134.833333 % of ImageWidth periodic points z = 0.0000000000000000 +0.0000000000000000*i z = -0.1225611668766540 +0.7448617666197440*i z = -0.6623589786223729 +0.5622795120623005*i gcc version: 11.2.0 __STDC__ = 1 __STDC_VERSION__ = 201710 c dialect = C18
From console :
chmod +x j.sh ./j.sh make pgm files display OMP info run the compiled program 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 = '1' OMP_NUM_TEAMS = '0' OMP_TEAMS_THREAD_LIMIT = '0' 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' OMP_ALLOCATOR = 'omp_default_mem_alloc' OMP_TARGET_OFFLOAD = 'DEFAULT' OPENMP DISPLAY ENVIRONMENT END setup start end of setup compute image 3 19999 from 19999 compute image 7 19999 from 19999 allways free memory (deallocate ) to avoid memory leaks real 0m38,531s user 3m48,484s sys 0m2,858s change Image Magic settings convert all pgm files to png using Image Magic v 6 convert LCM.pgm LSCM.pgm LSM.pgm MBD_LCM.pgm MBD_LSCM.pgm MBD_LSM_LCM.pgm MBD_LSM_LSCM.pgm MBD.pgm delete all pgm files OK info about software GNU bash, wersja 5.1.16(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2020 Free Software Foundation, Inc. Licencja GPLv3+: GNU GPL wersja 3 lub późniejsza <http://gnu.org/licenses/gpl.html> To oprogramowanie jest wolnodostępne; można je swobodnie zmieniać i rozpowszechniać. Nie ma ŻADNEJ GWARANCJI w granicach dopuszczanych przez prawo. GNU Make 4.3 Ten program został zbudowany dla systemu x86_64-pc-linux-gnu Copyright (C) 1988-2020 Free Software Foundation, Inc. Licencja GPLv3+: GNU GPL wersja 3 lub nowsza <http://gnu.org/licenses/gpl.html> To oprogramowanie jest wolnodostępne: można je swobodnie zmieniać i rozpowszechniać. Nie ma ŻADNEJ GWARANCJI w zakresie dopuszczalnym przez prawo. gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Version: ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org Copyright: (C) 1999-2021 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php Features: Cipher DPC Modules OpenMP(4.5) Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib Resource limits: Width: 1MP Height: 1MP List length: unlimited Area: 128MP Memory: 256MiB Map: 512MiB Disk: 10GiB File: 768 Thread: 8 Throttle: 0 Time: unlimited
Items portrayed in this file
depicts
some value
3 May 2022
image/png
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 04:16, 12 June 2022 | 2,000 × 2,000 (639 KB) | Soul windsurfer | cimag, not creal | |
14:42, 3 May 2022 | 2,000 × 2,000 (803 KB) | Soul windsurfer | Uploaded own work with UploadWizard |
File usage
The following 3 pages use this file:
Global file usage
The following other wikis use this file:
- Usage on en.wikipedia.org
Metadata
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.
PNG file comment |
|
---|---|
File change date and time | 03:58, 12 June 2022 |