-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj.c
1900 lines (1045 loc) · 42.4 KB
/
j.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
https://arxiv.org/pdf/1510.00043v2.pdf
Parabolic and near-parabolic renormalizations for local degree three by Fei Yang
B3 is a Blaschke product whose Julia set is the unit circle. The point z = 1
is a 1-parabolic fixed point with two attracting petals. In particular, the unit disk D
and C rb D are two immediate basins of 1
the first column of figure 14 indicate the dynamical chessboards of f and B3.
B3
(%i9) display2d:false;
(%o9) false
(%i10) a;
(%o10) ((z+1/2)/(z/2+1))^3
(%i11) ratsimp(a);
(%o11) (8*z^3+12*z^2+6*z+1)/(z^3+6*z^2+12*z+8)
(%i12) ratexpand(a);
(%o12) (8*z^3)/(z^3+6*z^2+12*z+8)+(12*z^2)/(z^3+6*z^2+12*z+8)
+(6*z)/(z^3+6*z^2+12*z+8)
+1/(z^3+6*z^2+12*z+8)
t B3 is a Blaschke product whose Julia set is the unit circle. The point z = 1
is a 1-parabolic fixed point with two attracting petals.
In particular, the unit disk D and C rb D are two immediate basins of 1.
the dynamical chessboards of f and B3.
here are:
* 1 critical point z=0.0
* 1 a nondegenerated 1-parabolic fixed point
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 ------------------------------------------------------------ */
//
/*
FunctionType = representing functions
BD = Binary decomposition
MBD = Modified BD is better, so BD is not used
*/
typedef enum {FatouBasins = 0, FatouComponents = 2, LSM = 3, LS2M = 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, ParabolicCheckerboard2 = 17
} FunctionTypeT;
// FunctionTypeT FunctionType;
// virtual 2D array and integer ( screen) coordinate
// Indexes of array starts from 0 not 1
//unsigned int ix, iy; // var
static unsigned int ixMin = 0; // Indexes of array starts from 0 not 1
static unsigned int ixMax; //
static unsigned int iWidth; // horizontal dimension of array
static unsigned int iyMin = 0; // Indexes of array starts from 0 not 1
static unsigned int iyMax; //
static unsigned int iHeight = 2000; //
// 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
// see SetPlane
double radius = 1.5;
complex double plane_center = 0.0 ;
double DisplayAspectRatio = 1.0; // https://en.wikipedia.org/wiki/Aspect_ratio_(image)
// dx = dy compare setup : iWidth = iHeight;
double ZxMin; //= -1.3; //-0.05;
double ZxMax;// = 1.3; //0.75;
double ZyMin;// = -1.3; //-0.1;
double ZyMax;// = 1.3; //0.7;
double PixelWidth; // =(ZxMax-ZxMin)/ixMax;
double PixelHeight; // =(ZyMax-ZyMin)/iyMax;
double ratio;
complex double trap_center;
complex double trap_center2;
double ER;
double ER2; //= 1e60;
double AR; // bigger values do not works
double AR2;
int IterMax = 1000;
int IterMax_LSM = 1000;
//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 iColorOfInterior1 = 250;
unsigned char iColorOfExterior = 225;
// 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
unsigned long long int uUnknown = 0;
unsigned long long int uInterior = 0;
unsigned long long int uExterior = 0;
/* critical point */
const int period = 1;
complex double zcr = -0.5; //
complex double c ;
//
complex double zp0; // a nondegenerated 1-parabolic fixed point
// 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
//
/* ------------------------------------------ functions -------------------------------------------------------------*/
/*
*/
// complex function b3
complex double f(const complex double z0) {
double complex z = z0;
// ((z+1/2)/(z/2+1))^3
complex double n = z +0.5;
complex double d = 1.0 +(z/2.0);
z = cpow(n/d, 3.0);
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 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 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 ){
//if ( r<rMin) {break;}
z = f(z); // forward iteration
}
// check distance between zn = f^n(zcr) and periodic point zp0
r = cabs(z - zp0)/2.0;
// 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(trap_center -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(trap_center2-z) < AR2 ){ return iColorOfInterior1;}
// 1 Attraction basins
if ( cabs2(trap_center-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(trap_center-z) < AR2 ){ return iColorOfBasin1 - (i % period)*20;}
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)
{
//double cabs2z;
//double cabs2zAR;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
//cabs2z = cabs2(z);
//cabs2zAR = cabs2(trap_center - z);
// infinity is superattracting here !!!!!
if ( cabs2(trap_center2-z) < AR2 || ( cabs2(trap_center-z) < AR2 ))
{ return (15*i) % 255;} // cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
z = f(z);
}
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 ComputeColorOfLS2M (complex double z)
{
double cabs2z;
double cabs2zAR;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
//cabs2z = cabs2(z);
//cabs2zAR = cabs2(trap_center - z);
if ( cabs2(trap_center2-z) < AR2 || ( cabs2(trap_center-z) < AR2 ))
{
if (i %2)
{return 255;}
else {return 230;}}
//return (15*i) % 255;} // cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
z = f(z);
}
return iColorOfUnknown;
}
unsigned char ComputeColorOfBD (complex double z)
{
double cabs2z;
double cabs2zAR;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
//cabs2z = cabs2(z); // numerical speed up : cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
//cabs2zAR = cabs2(trap_center - z);
//
if ( cabs2(trap_center2-z) < AR2 || ( cabs2(trap_center-z) < AR2 ) ) // if z is inside target set ( orbit trap)
{
if (creal(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 cabs2zAR;
double turn;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z); // numerical speed up : cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
cabs2zAR = cabs2(trap_center - z);
// if z is inside target set ( orbit trap) = exterior of circle with radius ER
if ( cabs2z > ER2 ) // exterior
{
if (creal(z) > 0) // binary decomposition of target set
{ return 150;}
else {return 255; }
}
if ( cabs2zAR < 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 150;}
else {return 255; }
}
z = f(z);
}
return iColorOfUnknown;
}
// Modified BD
unsigned char ComputeColorOfIBD (complex double z)
{
double cabs2z;
double cabs2zAR;
double turn;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z); // numerical speed up : cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
cabs2zAR = cabs2(trap_center - z);
// if z is inside target set ( orbit trap) = exterior of circle with radius ER
if ( cabs2z > ER2 ) // exterior
{
return iColorOfExterior;
}
if ( cabs2zAR < 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 150;}
else {return 255; }
}
z = f(z);
}
return iColorOfUnknown;
}
//
unsigned char ComputeColorOfParabolicCheckerboard (complex double z)
{
double cabs2z;
double cabs2zAR;
//double turn;
int m;
int n;
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z); // numerical speed up : cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
cabs2zAR = cabs2(trap_center - z);
// if z is inside target set ( orbit trap) = exterior of circle with radius ER
if ( cabs2z > ER2 ) // exterior
{
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;
}
//
unsigned char ComputeColorOfParabolicCheckerboard2 (complex double z)
{
double cabs2z;
double cabs2zAR;
double angle;
int pMax = 6; // ? child period ?
int i; // number of iteration
for (i = 0; i < IterMax_LSM; ++i)
{
cabs2z = cabs2(z); // numerical speed up : cabs2(zp0-z) = cabs2(z) because zp0 = zcr = 0
cabs2zAR = cabs2(trap_center - z);
// if z is inside target set ( orbit trap) = exterior of circle with radius ER
if ( cabs2z > ER2 ) // exterior
{
return iColorOfExterior;
}
for (int p=0; p < pMax; p++){
if ( cabs2zAR < AR2 ) // if z is inside target set ( orbit trap) = interior of cirlce with radius AR
{
angle = c_turn(z - trap_center); // now in (0,1) range
angle = angle*200.0; // repeated gradient
return angle* 255; // now in (0,255) range
}
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 LS2M : {iColor = ComputeColorOfLS2M(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 ; //