-
Notifications
You must be signed in to change notification settings - Fork 1
/
FractintFunctions.cpp
1413 lines (1285 loc) · 35.9 KB
/
FractintFunctions.cpp
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
/*
FRACTINTFUNCTIONS.CPP a module for the per pixel calculations of fractals originally from Fractint
Written in Microsoft Visual 'C++' by Paul de Leeuw.
This program is written in "standard" C. Hardware dependant code
(console drivers & serial I/O) is in separate machine libraries.
*/
#include <math.h>
#include "manp.h"
#include "fractype.h"
#include "Complex.h"
#include "pixel.h"
#include "bif.h"
/**************************************************************************
Initialise functions for each pixel
**************************************************************************/
int CPixel::InitFractintFunctions(WORD type, Complex *z, Complex *q)
{
switch (type)
{
case NEWTON:
case NEWTBASIN:
case MPNEWTBASIN:
case MPNEWTON:
// The roots of a polynomial function of the form x^n - 1 = 0.
// Newton's method to determine the root of f(x) = 0, given a value of x:
// DO WHILE(abs(x2 - x1) >= delta1 or abs(f(x2) > delta2 or f'(x1) != 0)
// set x2 = x1 - f(x1) / f'(x1)
// set x1 = x2
// ENDDO
*degree = (int)param[0]; // so we have to get the degrees and subtype from the parameters
if (*degree < 2)
*degree = 3; // defaults to 3, but 2 is possible
switch ((int)param[1])
{
case 0:
subtype = 'N';
break;
case 1:
subtype = 'S';
break;
case 2:
subtype = 'B';
break;
default:
subtype = 'N';
break;
}
root = 1; // set up table of roots of 1 along unit circle
// precalculated values
thresh = 0.3 * PI / (double)*degree; // less than half distance between roots
if (subtype == 'S' || subtype == 'B')
{
if (*degree > MAXROOTS)
*degree = MAXROOTS;
// list of roots to discover where we converged for newtbasin
for (int i = 0; i < *degree; i++)
{
roots[i].x = cos(i*PI*2.0 / (double)*degree);
roots[i].y = sin(i*PI*2.0 / (double)*degree);
}
}
period_level = FALSE; // no periodicity checking
*color = 0;
if (!juliaflag)
*z = *q / 3;
break;
case COMPLEXMARKSMAND: // Complex Mark's Mandelbrot
{
Complex pwr;
if (!juliaflag)
{
z->x = q->x + param[0];
z->y = q->y + param[1];
}
sqr = 0;
real_imag = 0.0;
pwr.x = param[2] - 1.0;
pwr.y = param[3];
Coefficient = *q ^ pwr;
break;
}
case SPIDERFP: // Spider(XAXIS) { c=z=pixel: z=z*z+c; c=c/2+z, |z|<=4 }
if (!juliaflag)
{
z->x = q->x + param[0];
z->y = q->y + param[1];
}
sqr = 0.0;
real_imag = 0.0;
temp = *q;
break;
case MANOWARFP: // From Art Matrix via Lee Skinner
case MANOWARJFP: // to handle fractint par files
case MANOWARJ: // to handle fractint par files
case MANOWAR: // to handle fractint par files
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
t = (invert) ? invertz2(*c) : *c;
if (juliaflag)
{
*z = t;
temp.x = q->x;
temp.y = q->y;
}
else
{
z->x = temp.x = t.x + param[0];
z->y = temp.y = t.y + param[1];
}
sqr.x = sqr(z->x);
sqr.y = sqr(z->y);
temp1 = *z;
break;
case BARNSLEYM1:
case BARNSLEYM2:
case BARNSLEYM3:
case BARNSLEYJ1:
case BARNSLEYJ2:
case BARNSLEYJ3:
case BARNSLEYM1FP:
case BARNSLEYM2FP:
case BARNSLEYM3FP:
case BARNSLEYJ1FP:
case BARNSLEYJ2FP:
case BARNSLEYJ3FP:
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
// t = (invert) ? invertz2(*c) : *c;
temp.x = q->x;
temp.y = q->y;
temp2.x = 0.0;
temp2.y = 0.0;
if (juliaflag)
*z = *c;
break;
case COMPLEXNEWTON:
case COMPLEXBASIN:
croot = 1;
cdegree = 3;
croot.x = param[2];
croot.y = param[3];
cdegree.x = param[0];
cdegree.y = param[1];
thresh = 0.3 * PI / cdegree.x; // less than half distance between roots
*z = *q;
subtype = ((int)param[4] == 0.0) ? 'N' : 'B';
break;
case ESCHER: // Science of Fractal Images pp. 185, 187
InitFunctions(MANDELFP, z, q);
break;
case MANDELLAMBDAFP: // variation of classical Mandelbrot/Julia
case MANDELLAMBDA:
case LAMBDAFP:
case LAMBDA:
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
if (juliaflag)
{
temp.x = q->x;
temp.y = q->y;
}
else
{
z->x = q->x + param[0];
z->y = q->y + param[1];
temp.x = z->x;
temp.y = z->y;
*z = 0.5;
}
sqr.x = sqr(z->x); // precalculated value for regular Mandelbrot
sqr.y = sqr(z->y);
break;
case PHOENIXFP:
case PHOENIX:
case MANDPHOENIXFP:
case MANDPHOENIX:
t = (invert) ? invertz2(*c) : *c;
temp.x = param[0];
temp.y = param[1];
temp2.x = param[2];
temp2.y = param[3];
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
if (juliaflag)
{
temp.x = q->x;
temp.y = q->y;
}
else
{
if (type == MANDPHOENIXFP)
*z = temp = t;
else
*z = t;
}
temp3 = 0; // set temp3 to Y value
PhoenixDegree = (int)temp2.x;
if (PhoenixDegree < 2 && PhoenixDegree > -3)
PhoenixDegree = 0;
param[2] = (double)PhoenixDegree;
if (PhoenixDegree == 0)
PhoenixType = ZERO;
if (PhoenixDegree >= 2)
{
PhoenixDegree = PhoenixDegree - 1;
PhoenixType = PLUS;
}
if (PhoenixDegree <= -3)
{
PhoenixDegree = abs(PhoenixDegree);
PhoenixDegree -= 2;
PhoenixType = MINUS;
}
break;
case MANDPHOENIXFPCPLX:
case MANDPHOENIXCPLX:
case PHOENIXCPLX:
case PHOENIXFPCPLX:
t = (invert) ? invertz2(*c) : *c;
temp.x = param[0];
temp.y = param[1];
temp2.x = param[2];
temp2.y = param[3];
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
if (juliaflag)
{
temp.x = q->x;
temp.y = q->y;
}
else
{
z->x = t.x + param[0];
z->y = t.y + param[1];
}
temp3 = 0; // set temp3 to Y value
PhoenixDegree = (int)param[4];
if (PhoenixDegree < 2 && PhoenixDegree > -3)
PhoenixDegree = 0;
param[4] = (double)PhoenixDegree;
if (PhoenixDegree == 0)
{
if (temp2.x != 0 || temp2.y != 0)
*symmetry = NOSYM;
else
*symmetry = ORIGIN;
if (temp.y == 0 && temp2.y == 0)
*symmetry = XAXIS;
PhoenixType = ZERO;
}
if (PhoenixDegree >= 2)
{
PhoenixDegree = PhoenixDegree - 1;
if (temp.y == 0 && temp2.y == 0)
*symmetry = XAXIS;
else
*symmetry = NOSYM;
PhoenixType = PLUS;
}
if (PhoenixDegree <= -3)
{
PhoenixDegree = abs(PhoenixDegree);
PhoenixDegree -= 2;
if (temp.y == 0 && temp2.y == 0)
*symmetry = XAXIS;
else
*symmetry = NOSYM;
PhoenixType = MINUS;
}
break;
case FPMANDELZPOWER:
case LJULIAZPOWER:
case FPMANZTOZPLUSZPWR:
case FPJULZTOZPLUSZPWR:
case TETRATEFP: // Tetrate(XAXIS) { c=z=pixel: z=c^z, |z|<=(P1+3)
t = (invert) ? invertz2(*c) : *c;
temp.x = param[0];
temp.y = param[1];
temp2.x = param[2];
temp2.y = param[3];
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
if (juliaflag)
{
temp.x = q->x;
temp.y = q->y;
}
else
{
z->x = t.x + param[0];
z->y = t.y + param[1];
}
sqr.x = sqr(z->x);
sqr.y = sqr(z->y);
temp1 = *z; // set temp3 to Y value
break;
case MARKSMANDELFP:
case MARKSMANDEL:
case MARKSJULIAFP:
case MARKSJULIA:
{
Complex pwr;
t = (invert) ? invertz2(*c) : *c;
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
if (juliaflag)
{
t.x = q->x;
t.y = q->y;
}
else
{
z->x = t.x + param[0];
z->y = t.y + param[1];
}
sqr = 0;
real_imag = 0.0;
pwr.x = param[2] - 1.0;
pwr.y = 0;
Coefficient = *q ^ pwr;
break;
}
case QUATFP:
case QUATJULFP:
t = (invert) ? invertz2(*c) : *c;
temp = 0;
if (juliaflag)
{
*z = t;
qc = q->x;
qci = q->y;
}
else
{
*z = 0;
qc = t.x;
qci = t.y;
}
qcj = param[2];
qck = param[3];
break;
case UNITYFP: // Unity Fractal - brought to you by Mark Peterson - you won't find this in any fractal books unless they saw it here first - Mark invented it!
case SIERPINSKI: // following code translated from basic - see "Fractals Everywhere" by Michael Barnsley, p. 251, Program 7.1.1
case SIERPINSKIFP:
if (!juliaflag)
*z = *q;
period_level = FALSE; // no periodicity checking
break;
case VL: // Beauty of Fractals pp. 125 - 127
t = (invert) ? invertz2(*c) : *c;
temp.x = param[0];
temp.y = param[1];
temp2.x = param[2];
temp2.y = param[3];
period_level = FALSE; // no periodicity checking (get rid of bug 31/7/00 PHD)
if (juliaflag)
{
temp.x = q->x;
temp.y = q->y;
}
else
{
z->x = t.x + param[0];
z->y = t.y + param[1];
}
sqr.x = sqr(z->x);
sqr.y = sqr(z->y);
temp1 = *z; // set temp3 to Y value
if (param[0] < 0.0) param[0] = 0.0;
if (param[1] < 0.0) param[1] = 0.0;
if (param[0] > 1.0) param[0] = 1.0;
if (param[1] > 1.0) param[1] = 1.0;
break;
case MAGNET1M:
case MAGNET1J:
InitTierazonFunctions(102, z, q);
break;
case MAGNET2M:
case MAGNET2J:
InitTierazonFunctions(103, z, q);
break;
/******************* standalone engine for "lyapunov" ********************
Roy Murphy [76376,721]
revision history:
initial version: Winter '91
Fall '92 integration of Nicholas Wilt's ASM speedups
Jan 93' integration with calcfrac() yielding boundary tracing,
tesseral, and solid guessing, and inversion, inside=nnn
save_release behavior:
1730 & prior: ignores inside=, calcmode='1', (a,b)->(x,y)
1731: other calcmodes and inside=nnn
1732: the infamous axis swap: (b,a)->(x,y),
the order parameter becomes a long int
**************************************************************************/
/*
This routine sets up the sequence for forcing the Rate parameter
to vary between the two values. It fills the array lyaRxy[] and
sets lyaLength to the length of the sequence.
The sequence is coded in the bit pattern in an integer.
Briefly, the sequence starts with an A the leading zero bits
are ignored and the remaining bit sequence is decoded. The
sequence ends with a B. Not all possible sequences can be
represented in this manner, but every possible sequence is
either represented as itself, as a rotation of one of the
representable sequences, or as the inverse of a representable
sequence (swapping 0s and 1s in the array.) Sequences that
are the rotation and/or inverses of another sequence will generate
the same lyapunov exponents.
A few examples follow:
number sequence
0 ab
1 aab
2 aabb
3 aaab
4 aabbb
5 aabab
6 aaabb (this is a duplicate of 4, a rotated inverse)
7 aaaab
8 aabbbb etc.
*/
case LYAPUNOV:
{
long i, k;
int save_release = 0;
char TempSeq[120];
char *p;
if ((filter_cycles = (WORD)(param[2])) == 0)
filter_cycles = threshold / 2;
lyaSeedOK = param[0] > 0 && param[0] <= 1;
lyaLength = (int)strlen(LyapSequence);
strcpy(TempSeq, LyapSequence);
/*
i = (long)(param[0]);
lyaRxy[0] = 1;
for (t = 32; t >= 0; t--)
if (i & (1 << t)) break;
for (; t >= 0; t--)
lyaRxy[lyaLength++] = (i & (1 << t)) != 0;
lyaRxy[lyaLength++] = 0;
if (save_release < 1732) // swap axes prior to 1732
for (t = lyaLength; t >= 0; t--)
lyaRxy[t] = !lyaRxy[t];
*/
p = TempSeq; // better make sure we have no silly characters
for (i = 0, k = 0; i < lyaLength; i++)
{
char c = toupper(*(TempSeq + i));
if (c == 'A' || c == 'B' || c == 'C')
{
switch (c)
{
case 'A':
lyaRxy[k] = 0;
break;
case 'B':
lyaRxy[k] = 1;
break;
case 'C':
lyaRxy[k] = 2;
break;
}
LyapSequence[k] = c;
k++;
}
}
LyapSequence[k] = '\0';
lyaLength = (int)strlen(LyapSequence);
/*
for (i = 0; i < 1; i++)
{
lyaRxy[i] = 1;
lyaRxy[i + 2] = 0;
}
lyaLength = 2;
*/
// DisplayLyapSequence(lyaRxy, lyaLength);
}
break;
case FROTH:
{
if (param[0] != 3 && param[0] != 6) // if no match then
param[0] = 3; // make it 3
frothsix = param[0] == 6;
froth_altcolor = param[1] != 0;
froth_shades = (colors - 1) / (frothsix ? 6 : 3);
if (rqlim < 6.0)
rqlim = 6.0; // rqlim needs to be at least 6 or so
set_Froth_palette(hwnd); // make the best of the .map situation
// orbit_color = !frothsix && colors >= 16 ? (froth_shades<<1)+1 : colors-1;
}
break;
}
return 0;
}
/**************************************************************************
Run functions for each iteration
**************************************************************************/
int CPixel::RunFractintFunctions(WORD type, Complex *z, Complex *q, BYTE *SpecialFlag, long *iteration)
{
switch (type)
{
case NEWTON:
case NEWTBASIN:
case MPNEWTBASIN:
case MPNEWTON:
{
int tmpcolor;
int i;
color = iteration;
z2 = *z;
z1 = z->CPolynomial(*degree - 1);
*z = *z - (z1 * *z - *q - 1) / (z1 * *degree);
zd = *z - z2;
d = zd.CSumSqr();
if (d < MINSIZE)
{
if (subtype == 'S' || subtype == 'B')
{
tmpcolor = -1;
// this code determines which degree-th root of root the Newton formula converges to.
// The roots of a 1 are distributed on a circle of radius 1 about the origin.
for (i = 0; i < *degree; i++)
{
// color in alternating shades with iteration according to which root of 1 it converged to
if (distance(roots[i], z2) < thresh)
{
if (subtype == 'S')
tmpcolor = 1 + (i & 7) + ((*color & 1) << 3);
else
tmpcolor = 1 + i;
break;
}
}
if (tmpcolor == -1)
*color = threshold;
else
*color = tmpcolor;
}
return(TRUE);
}
else
return(FALSE);
}
case COMPLEXMARKSMAND: // Complex Mark's Mandelbrot
sqr.x = sqr(z->x);
sqr.y = sqr(z->y);
real_imag = z->x * z->y;
z->x = sqr.x - sqr.y;
z->y = real_imag + real_imag;
*z = Coefficient * *z + *q;
return BailoutTest(z, sqr);
case SPIDERFP: // Spider(XAXIS) { c=z=pixel: z=z*z+c; c=c/2+z, |z|<=4 }
sqr.x = sqr(z->x);
sqr.y = sqr(z->y);
real_imag = z->x * z->y;
z->x = sqr.x - sqr.y + temp.x;
z->y = 2 * real_imag + temp.y;
temp.x = temp.x / 2 + z->x;
temp.y = temp.y / 2 + z->y;
return BailoutTest(z, sqr);
case MANOWARFP: // From Art Matrix via Lee Skinner
case MANOWARJFP: // to handle fractint par files
case MANOWARJ: // to handle fractint par files
case MANOWAR: // to handle fractint par files
sqr.x = sqr(z->x);
sqr.y = sqr(z->y);
temp3.x = sqr.x - sqr.y + temp.x + temp1.x + param[0];
temp3.y = 2.0 * z->x * z->y + temp.y + temp1.y + param[1];
temp1 = *z;
d = z->CSumSqr();
*z = temp3;
return BailoutTest(z, sqr);
case BARNSLEYM1: // Barnsley's Mandelbrot type M1 from "Fractals Everywhere" by Michael Barnsley, p. 322
case BARNSLEYJ1:
case BARNSLEYM1FP:
case BARNSLEYJ1FP:
// calculate intermediate products
foldxinitx = z->x * temp.x;
foldyinity = z->y * temp.y;
foldxinity = z->x * temp.y;
foldyinitx = z->y * temp.x;
// orbit calculation
if (z->x >= 0)
{
// z->x = (foldxinitx - q->x - foldyinity + param[0]);
// z->y = (foldyinitx - q->y + foldxinity + param[1]);
temp1.x = foldxinitx - temp.x - foldyinity/* + param[0]*/; // param removed as it splatters julia
temp1.y = foldyinitx - temp.y + foldxinity/* + param[1]*/;
}
else
{
// z->x = (foldxinitx + q->x - foldyinity + param[0]);
// z->y = (foldyinitx + q->y + foldxinity + param[1]);
temp1.x = foldxinitx + temp.x - foldyinity/* + param[0]*/;
temp1.y = foldyinitx + temp.y + foldxinity/* + param[1]*/;
}
*z = temp1;
return FractintBailoutTest(z);
case BARNSLEYM2: // An unnamed Mandelbrot/Julia function from "Fractals Everywhere" by Michael Barnsley, p. 331, example 4.2
case BARNSLEYJ2:
case BARNSLEYM2FP:
case BARNSLEYJ2FP:
// calculate intermediate products
foldxinitx = z->x * temp.x;
foldyinity = z->y * temp.y;
foldxinity = z->x * temp.y;
foldyinitx = z->y * temp.x;
// orbit calculation
if (foldxinity + foldyinitx >= 0)
{
temp1.x = foldxinitx - temp.x - foldyinity/* + param[0]*/; // param removed as it splatters julia
temp1.y = foldyinitx - temp.y + foldxinity/* + param[1]*/;
}
else
{
temp1.x = foldxinitx + temp.x - foldyinity/* + param[0]*/;
temp1.y = foldyinitx + temp.y + foldxinity/* + param[1]*/;
}
*z = temp1;
return FractintBailoutTest(z);
case BARNSLEYM3: // An unnamed Mandelbrot/Julia function from "Fractals Everywhere" by Michael Barnsley, p. 292, example 4.1
case BARNSLEYJ3:
case BARNSLEYM3FP:
case BARNSLEYJ3FP:
// calculate intermediate products
foldxinitx = z->x * z->x;
foldyinity = z->y * z->y;
foldxinity = z->x * z->y;
// orbit calculation
if (z->x > 0)
{
temp1.x = foldxinitx - foldyinity - 1.0/* + param[0]*/; // param removed as it splatters julia
temp1.y = foldxinity * 2/* + param[1]*/;
}
else
{
temp1.x = foldxinitx - foldyinity - 1.0 + temp.x * z->x/* + param[0]*/;
temp1.y = foldxinity * 2/* + param[1]*/;
// This term added by Tim Wegner to make dependent on the imaginary part of the parameter. (Otherwise Mandelbrot is uninteresting).
temp1.y += temp.y * z->x;
}
*z = temp1;
return FractintBailoutTest(z);
case COMPLEXNEWTON:
case COMPLEXBASIN:
{
double mod;
int coloriter;
Complex tmp, temp, cd1, New;
double MPthreshold = 0.001;
// New = ((cdegree-1) * old**cdegree) + croot
// ----------------------------------
// cdegree * old**(cdegree-1)
*color = *iteration;
cd1.x = cdegree.x - 1.0;
cd1.y = cdegree.y;
// temp = CComplexPower(z, cd1);
temp = *z ^ cd1;
New = temp * *z;
tmp = New - croot;
if (tmp.CSumSqr() < MPthreshold)
{
if (subtype == 'N')
return(1);
if (fabs(z->y) < .01)
z->y = 0.0;
temp = z->CLog();
tmp = temp * cdegree;
mod = tmp.y / TWO_PI;
coloriter = (long)mod;
if (fabs(mod - coloriter) > 0.5)
{
if (mod < 0.0)
coloriter--;
else
coloriter++;
}
coloriter += 2;
if (coloriter < 0)
coloriter += 128;
*iteration = coloriter; // PHD 2009-10-13
return(1);
}
tmp = New * cd1;
tmp += croot;
// tmp.x += croot.x;
// tmp.y += croot.y;
cd1 = temp * cdegree;
*z = tmp / cd1;
return(0);
}
case ESCHER: // Science of Fractal Images pp. 185, 187
{
Complex oldtest, newtest, testsqr;
double testsize = 0.0;
int testiter = 0;
sqr.x = z->x * z->x;
sqr.y = z->y * z->y;
temp.x = sqr.x - sqr.y; // standard Julia with C == (0.0, 0.0i)
temp.y = 2.0 * z->x * z->y;
oldtest.x = temp.x * 15.0; // scale it
oldtest.y = temp.y * 15.0;
testsqr.x = sqr(oldtest.x); // set up to test with user-specified ...
testsqr.y = sqr(oldtest.y); // ... Julia as the target set
// while (testsize <= rqlim && testiter < threshold) // nested Julia loop
while (TRUE) // nested Julia loop
{
if (testsize > rqlim)
break;
if (testiter >= threshold)
break;
newtest.x = testsqr.x - testsqr.y + param[0];
newtest.y = 2.0 * oldtest.x * oldtest.y + param[1];
testsize = (testsqr.x = sqr(newtest.x)) + (testsqr.y = sqr(newtest.y));
oldtest = newtest;
testiter++;
}
if (testsize > rqlim)
{
*z = temp;
return FractintBailoutTest(z);
}
else // make distinct level sets if point stayed in target set
{
// iteration = ((3L * iteration) % 255L) + 1L;
*iteration = ((3 * *iteration) % 255) + 1;
return 1;
}
}
case MANDELLAMBDAFP: // variation of classical Mandelbrot/Julia
case MANDELLAMBDA:
case LAMBDAFP:
case LAMBDA:
sqr.x = z->x * z->x;
sqr.y = z->y * z->y;
sqr.x = z->x - sqr.x + sqr.y;
sqr.y = -(z->y * z->x);
sqr.y += sqr.y + z->y;
z->x = temp.x * sqr.x - temp.y * sqr.y;
z->y = temp.x * sqr.y + temp.y * sqr.x;
return BailoutTest(z, sqr);
case PHOENIXFP:
case PHOENIX:
case MANDPHOENIXFP:
case MANDPHOENIX:
if (PhoenixType == ZERO)
return(PhoenixFractal(z, q));
else if (PhoenixType == PLUS)
return(PhoenixPlusFractal(z, q));
else
return(PhoenixMinusFractal(z, q));
return 1; // just to shut up compiler warnings
case MANDPHOENIXFPCPLX:
case MANDPHOENIXCPLX:
case PHOENIXCPLX:
case PHOENIXFPCPLX:
if (PhoenixType == ZERO)
return(PhoenixFractalcplx(z, q));
else if (PhoenixType == PLUS)
return(PhoenixCplxPlusFractal(z, q));
else
return(PhoenixCplxMinusFractal(z, q));
return 1; // just to shut up compiler warnings
case FPMANDELZPOWER:
*z = *z ^ temp2;
z->x += q->x + param[0];
z->y += q->y + param[1];
return FractintBailoutTest(z);
case FPMANZTOZPLUSZPWR:
case FPJULZTOZPLUSZPWR:
temp = z->CPolynomial((int)param[2]);
*z = *z ^ *z;
z->x = temp.x + z->x + q->x + param[0];
z->y = temp.y + z->y + q->y + param[1];
return FractintBailoutTest(z);
case MARKSMANDELFP: // Mark Peterson's variation of "lambda" function
case MARKSMANDEL:
case MARKSJULIAFP:
case MARKSJULIA:
// Z1 = (C^(exp-1) * Z**2) + C
sqr.x = z->x * z->x;
sqr.y = z->y * z->y;
temp.x = sqr.x - sqr.y;
temp.y = z->x * z->y * 2;
temp1.x = Coefficient.x * temp.x - Coefficient.y * temp.y + t.x;
temp1.y = Coefficient.x * temp.y + Coefficient.y * temp.x + t.y;
*z = temp1;
return BailoutTest(z, sqr);
case QUATFP:
case QUATJULFP:
{
double a0, a1, a2, a3, n0, n1, n2, n3, magnitude;
a0 = z->x;
a1 = z->y;
a2 = temp.x;
a3 = temp.y;
n0 = a0 * a0 - a1 * a1 - a2 * a2 - a3 * a3 + qc;
n1 = 2 * a0*a1 + qci;
n2 = 2 * a0*a2 + qcj;
n3 = 2 * a0*a3 + qck;
// Check bailout
magnitude = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
if (magnitude > rqlim) {
return 1;
}
z->x = n0;
z->y = n1;
temp.x = n2;
temp.y = n3;
return(0);
}
case SIERPINSKI: // following code translated from basic - see "Fractals Everywhere" by Michael Barnsley, p. 251, Program 7.1.1
case SIERPINSKIFP:
temp.x = z->x + z->x;
temp.y = z->y + z->y;
if (z->y > 0.5)
temp.y = temp.y - 1;
else if (z->x > 0.5)
temp.x = temp.x - 1;
// end barnsley code
*z = temp;
return FractintBailoutTest(z);
case TETRATEFP: // Tetrate(XAXIS) { c=z=pixel: z=c^z, |z|<=(P1+3)
*z = *q ^ *z;
return FractintBailoutTest(z);
case UNITYFP: // Unity Fractal - brought to you by Mark Peterson - you won't find this in any fractal books unless they saw it here first - Mark invented it!
temp.x = sqr(z->x) + sqr(z->y);
// if((XXOne > 2.0) || (fabs(XXOne - 1.0) < ddelmin))
if ((temp.x > 2.0) || (fabs(temp.x - 1.0) < 0.01))
return(1);
z->y = (2.0 - temp.x)* z->x;
z->x = (2.0 - temp.x)* z->y;
temp = *z; // PHD added this line
return(0);
case VL: // Beauty of Fractals pp. 125 - 127
{
double a, b, ab, half, u, w, xy;
half = param[0] / 2.0;
xy = z->x * z->y;
u = z->x - xy;
w = -z->y + xy;
a = z->x + param[1] * u;
b = z->y + param[1] * w;
ab = a * b;
temp.x = z->x + half * (u + (a - ab));
temp.y = z->y + half * (w + (-b + ab));
*z = temp;
return FractintBailoutTest(z);
}
case MAGNET1M:
case MAGNET1J:
return (RunTierazonFunctions(102, z, q, SpecialFlag, iteration));
case MAGNET2M:
case MAGNET2J:
return (RunTierazonFunctions(103, z, q, SpecialFlag, iteration));
case LYAPUNOV:
{
double ra, rb, rc; // r in the direction of x, y, and z or A, B, C
rc = param[2]; // add z component C - good for animation
overflow = FALSE;
if (param[0] == 1)
Population = (1.0 + rand()) / (2.0 + RAND_MAX);
else if (param[0] == 0)
{
if (fabs(Population) > BIG || Population == 0 || Population == 1)
Population = (1.0 + rand()) / (2.0 + RAND_MAX);
}
else Population = param[0];
{
ra = c->x;
rb = c->y;
}
*color = lyapunov_cycles(filter_cycles, ra, rb, rc);
z->x = Rate; // sort of to allow filters and FwdDiff to give something!!!
z->y = Population;
if (TrueCol->inside_colour > 0 && *color == 0)
*color = TrueCol->inside_colour;
else if (*color >= colors)
*color = colors - 1;
// (*plot)((WORD)col, (WORD)row, color);
*iteration = *color;
// return color;
return TRUE;
}
case FROTH: // Froth Fractal type - per pixel 1/2/g, called with row & col set
{
// These points were determined imperically and verified experimentally
// using the program WL-Plot, a plotting program which has a mode for
// orbits of recursive relations.
#define CLOSE 1e-6 // seems like a good value
#define SQRT3 1.732050807568877193
#define A 1.02871376822
#define B1 (A/2)
#define M2 SQRT3
#define B2 (-A)
#define M3 (-SQRT3)
#define B3 (-A)
#define X1MIN -1.04368901270
#define X1MAX 1.33928675524
#define XMIDT -0.339286755220
#define X2MAX1 0.96729063460
#define XMIDR 0.61508950585
#define X3MIN1 -0.22419724936
#define X2MIN2 -1.11508950586
#define XMIDL -0.27580275066
#define X3MAX2 0.07639837810
#define FROTH_BITSHIFT 28
int found_attractor = 0;
double magnitude;
double x, y, nx, ny, x2, y2;
double close = CLOSE;
double a = A;
double b1 = B1;
double xmidt = XMIDT;
double m2 = M2;
double b2 = B2;
double m3 = M3;
double b3 = B3;
double x1min = X1MIN;