-
Notifications
You must be signed in to change notification settings - Fork 27
/
standard.ucl
1804 lines (1714 loc) · 51.1 KB
/
standard.ucl
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
comment {
This file contains standard coloring algorithms for Ultra Fractal 3.
Many of the coloring algorithms here were written by other formula
authors, as noted in the comments with each formula. All formulas
have been edited and simplified by Frederik Slijkerman.
}
BinaryDecomposition {
;
; Classic binary decomposition. Can give quite abstract effects.
; Use low bail-out values in the fractal formula (if possible) for
; best effects. This coloring algorithm uses just two colors from
; the gradient: one from the left end and one from the middle.
;
final:
if @type == "Type 1"
if real(#z) * imag(#z) >= 0
#index = 0.5
else
#index = 0
endif
else
if atan2(#z) > 0
#index = 0.5
else
#index = 0
endif
endif
default:
title = "Binary Decomposition"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/binarydecomposition.html"
param type
caption = "Decomposition Type"
enum = "Type 1" "Type 2"
default = 0
hint = "Toggles between two types of binary decomposition. Type 2 \
reproduces the coloring used with many images in the classic \
Beauty of Fractals book."
endparam
}
Gradient {
;
; Shows the entire gradient in various ways. The fractal formula
; is ignored. Use zooming, panning and rotating to get the desired
; gradient. Make sure that Repeat Gradient is enabled.
;
final:
if @type == "Linear"
#index = 16.5 + 0.25 * real(#pixel)
elseif @type == "Radial"
#index = 0.2 * |#pixel|
else
#index = 0.5 - atan2(#pixel) / (2 * #pi)
endif
default:
title = "Gradient"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/gradient.html"
param type
caption = "Gradient Type"
enum = "Linear" "Radial" "Cone"
hint = "Specifies the shape of the gradient."
endparam
}
Default {
;
; Reproduces the iterations coloring algorithm found in most fractal
; software. This is the coloring algorithm that is used by default in
; Ultra Fractal when no coloring algorithm is loaded. See also the
; Basic coloring algorithm.
;
final:
#index = 0.01 * #numiter
default:
title = "None"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/none.html"
}
Basic(OUTSIDE) {
;
; Four basic and classic ways to color a fractal. Other classic
; algorithms are Decomposition, Binary Decomposition, and
; Distance Estimator.
;
final:
if @type == "Iteration"
#index = 0.01 * #numiter
elseif @type == "Real"
#index = 0.05 * (4 + real(#z))
elseif @type == "Imaginary"
#index = 0.05 * (4 + imag(#z))
else
#index = 0.05 * (4 + real(#z) + imag(#z))
endif
default:
title = "Basic"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/basic.html"
param type
caption = "Coloring Type"
enum = "Iteration" "Real" "Imaginary" "Sum"
hint = "Specifies how the fractal is colored. Most options work best \
with low bail-out values for the fractal formula, like 4. \
The Iteration option is the classic way to color fractals."
endparam
}
Decomposition {
;
; Decomposes the angle of the Z variable after iteration
; and distributes it over the gradient. See also the
; Binary Decomposition coloring algorithm.
;
; Written by Damien M. Jones
;
final:
float d = atan2(#z); get angle of z
IF (d < 0); it's negative
d = d + #pi * 2; make it positive
ENDIF
#index = d / (#pi * 2)
default:
title = "Decomposition"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/decomposition.html"
}
Triangle {
;
; Variation on the Triangle Inequality Average coloring method
; from Kerry Mitchell. The smoothing used here is based on the
; Smooth formula, which only works for z^n+c and derivates.
;
; Written by Damien M. Jones
;
init:
float sum = 0.0
float sum2 = 0.0
float ac = cabs(#pixel)
float il = 1/log(@power)
float lp = log(log(@bailout)/2.0)
float az2 = 0.0
float lowbound = 0.0
float f = 0.0
BOOL first = true
loop:
sum2 = sum
IF (!first)
az2 = cabs(#z - #pixel)
lowbound = abs(az2 - ac)
sum = sum + ((cabs(#z) - lowbound) / (az2+ac - lowbound))
ELSE
first = false
ENDIF
final:
sum = sum / (#numiter)
sum2 = sum2 / (#numiter-1)
f = il*lp - il*log(log(cabs(#z)))
#index = sum2 + (sum-sum2) * (f+1)
default:
title = "Triangle Inequality Average"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/triangleinequalityaverage.html"
param power
caption = "Exponent"
default = 2.0
hint = "This should be set to match the exponent of the \
formula you are using. For Mandelbrot, this is 2."
endparam
param bailout
caption = "Bailout"
default = 1e20
min = 1
hint = "This should be set to match the bail-out value in \
the Formula tab. Use a very high value for good results."
endparam
}
Lighting {
;
; Coloring algorithm for the Slope family of fractal types.
; This coloring algorithm performs 3D lighting for these
; fractals.
;
; Written by Damien M. Jones
;
final:
float vz = -sqrt(1-|#z|); extract implied portion of normal
float d2r = #pi/180; degrees to radians conversion factor
; create vector for light direction
float lx = cos((270-@angle)*d2r) * cos(@elevation*d2r)
float ly = sin((270-@angle)*d2r) * cos(@elevation*d2r)
float lz = -sin(@elevation*d2r)
; compute cosine of angle between these vectors
; (this is the amount of lighting on the surface)
float l = lx*real(#z) + ly*imag(#z) + lz*vz
IF (l < @ambient); light is below the ambient level
l = @ambient; set it to the ambient level
ENDIF
IF (@ambient < 0); the ambient level is negative
l = l + 1; offset to prevent clipping at 0
ENDIF
#index = l*0.99; reduce it just a bit to prevent
; the colors from wrapping
default:
title = "Lighting"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/lighting.html"
param @angle
caption = "Light Rotation"
default = 90.0
hint = "Gives the rotation of the light source, in degrees. With 0 \
degrees, the light comes from above. Positive values give \
clockwise rotation."
endparam
param @elevation
caption = "Light Elevation"
default = 30.0
hint = "Gives the elevation of the light source, in degrees."
endparam
param @ambient
caption = "Ambient Light"
default = 0.0
min = -1.0
max = 1.0
hint = "Specifies the level of ambient light. Use -1.0 to \
color all surfaces."
endparam
}
DistanceEstimator(OUTSIDE) {
;
; Distance-estimator coloring algorithm for Mandelbrot and
; other z^n fractal types (Phoenix, Julia). This coloring
; algorithm estimates the distance to the boundary of the
; fractal (for example the Mandelbrot set) and colors points
; accordingly.
;
; Written by Damien M. Jones
;
init:
complex dz = (0,0)
loop:
dz = @power * #z^(@power-1) * dz + 1
final:
#index = (@power*log(cabs(#z)) * cabs(#z) / cabs(dz))^(1/@power)
default:
title = "Distance Estimator"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/distanceestimator.html"
param power
caption = "Exponent"
default = 2.0
hint = "This should be set to match the exponent of the \
formula you are using. For Mandelbrot, this is 2."
endparam
}
Emboss {
;
; Coloring algorithm for the Embossed family of fractal types.
; This coloring algorithm performs 3D lighting for these fractals.
;
; Uses 3 colors from the gradient, at index values of 0.2, 0.5,
; and 0.8. With Color Density set to 1, Transfer Function set to
; Linear, and Gradient Offset set to 0, these index values
; corresponding to the gradient positions 80, 200, and 320.
;
; Written by Kerry Mitchell.
;
final:
if(real(#z)<imag(#z))
#index=0.2
elseif(imag(#z)<real(#z))
#index=0.8
else
#index=0.5
endif
default:
title="Emboss"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/emboss.html"
}
GaussianInteger {
;
; Colors by the relationship of the orbit of Z to Gaussian
; Integers.
;
; Written by Kerry Mitchell.
;
init:
float r=0.0
float rmin=1.0e12
float rmax=0.0
float rave=0.0
float total=0.0
float t=0.0
int iter=0
int itermin=0
int itermax=0
zmin=(0.0,0.0)
zmax=(0.0,0.0)
if(@norm==1) ; pixel normalization
normfac=#pixel
elseif(@norm==2) ; factor normalization
normfac=@fac
elseif(@norm==3) ; f(z) normalization
normfac=@normfunc(#z)
else ; no normalization
normfac=(1.0,0.0)
endif
float logfac=@logseed
loop:
iter=iter+1
temp2=#z
if @randomize
logfac=4*logfac*(1-logfac)
temp2=temp2*(1-@randomsize*logfac)
endif
if(@inttype==1) ; trunc
temp=trunc(temp2/normfac)
elseif(@inttype==2) ; floor
temp=floor(temp2/normfac)
elseif(@inttype==3) ; ceil
temp=ceil(temp2/normfac)
else ; round
temp=round(temp2/normfac)
endif
remain=temp2-temp*normfac
r=cabs(remain)
total=total+r
rave=total/iter
if(r<rmin)
rmin=r
zmin=temp2
itermin=iter
endif
if(r>rmax)
rmax=r
zmax=temp2
itermax=iter
endif
final:
if(@colorby==1) ; iteration @ min
#index=0.01*itermin
elseif(@colorby==2) ; angle @ min
t=atan2(zmin)
t=t/pi
if(t<0.0)
t=t+2.0
endif
#index=0.5*t
elseif(@colorby==3) ; maximum distance
#index=rmax
elseif(@colorby==4) ; iteration @ max
#index=0.01*itermax
elseif(@colorby==5) ; angle @ max
t=atan2(zmax)
t=t/pi
if(t<0.0)
t=t+2.0
endif
#index=0.5*t
elseif(@colorby==6) ; average distance
#index=rave
elseif(@colorby==7) ; min/mean/max angle
zmax=(rave-rmin)+flip(rmax-rave)
t=atan2(zmax)
t=t/pi
if(t<0.0)
t=t+2.0
endif
#index=0.5*t
elseif(@colorby==8) ; max/min ratio
#index=rmax/(rmin+1.e-12)
else ; minimum distance
#index=rmin
endif
default:
title="Gaussian Integer"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/gaussianinteger.html"
param inttype
caption="Integer Type"
default=0
enum="round(z)" "trunc(z)" "floor(z)" "ceil(z)"
endparam
param colorby
caption="Color By"
default=0
enum="minimum distance" "iteration @ min" "angle @ min" \
"maximum distance" "iteration @ max" "angle @ max" "average distance"\
"min/mean/max angle" "max/min ratio"
endparam
param norm
caption="Normalization"
default=0
enum="none" "pixel" "factor" "f(z)"
endparam
param fac
caption=" Factor"
default=(2.0,1.0)
hint = "Normalization factor."
visible = @norm == "factor"
endparam
func normfunc
caption=" Function"
default=ident()
hint = "Normalization function."
visible = @norm == "f(z)"
endfunc
param randomize
caption="Randomize"
default=false
hint="Applies a random factor to z every iteration before \
finding the Gaussian integer."
endparam
param randomsize
caption="Random Size"
default=(0.1,0)
hint="Size of random factor. Larger values give more randomization."
visible = @randomize
endparam
param logseed
caption="Random Seed"
default=0.1
min=0.0
max=1.0
hint="Randomize seed, between 0 and 1. Every seed gives a different \
image."
visible = @randomize
endparam
}
ExponentialSmoothing {
;
; This coloring method provides smooth iteration
; colors for all fractal types, convergent or
; divergent (or both). It combines the two methods
; developed by Ron Barnett. It doesn't map
; precisely to iterations, but it's close.
;
; Written by Damien M. Jones
;
init:
float sum = 0.0
float sum2 = 0.0
complex zold = (0,0)
loop:
IF (@diverge)
sum = sum + exp(-cabs(#z))
ENDIF
IF (@converge)
sum2 = sum2 + exp(-1/cabs(zold-#z))
ENDIF
zold = #z
final:
IF (|#z - zold| < 0.5); convergent bailout.
IF (@converge)
#index = sum2
ELSE
#index = 0
ENDIF
ELSE; divergent bailout.
IF (@diverge)
#index = sum * @divergescale
ELSE
#index = 0
ENDIF
ENDIF
default:
title = "Exponential Smoothing"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/exponentialsmoothing.html"
param diverge
caption = "Color Divergent"
default = FALSE
hint = "If set, points which escape to infinity will be \
colored."
endparam
param converge
caption = "Color Convergent"
default = TRUE
hint = "If set, points which collapse to one value will be \
colored."
endparam
param divergescale
caption = "Divergent Density"
default = 1.0
hint = "Sets the divergent coloring density, relative to the \
convergent coloring. If set to 1.0, they will use \
the same color density."
endparam
}
Smooth(OUTSIDE) {
;
; This coloring method provides smooth iteration
; colors for Mandelbrot and other z^2 formula types
; (Phoenix, Julia). Results on other types may be
; unpredictable, but might be interesting.
;
; Thanks to F. Slijkerman for some tweaks.
; Thanks to Linas Vepstas for the math.
;
; Written by Damien M. Jones
;
init:
complex il = 1/log(@power); Inverse log (power).
float lp = log(log(@bailout)); log(log bailout).
final:
#index = 0.05 * real(#numiter + il*lp - il*log(log(cabs(#z))))
default:
title = "Smooth (Mandelbrot)"
helpfile = "Uf3.chm"
helptopic = "Html/coloring/standard/smooth.html"
param power
caption = "Exponent"
default = (2,0)
hint = "This should be set to match the exponent of the \
formula you are using. For Mandelbrot, this is 2."
endparam
param bailout
caption = "Bail-out value"
default = 128.0
min = 1
hint = "This should be set to match the bail-out value in \
the Formula tab. This formula works best with bail-out \
values higher than 100."
endparam
}
OrbitTraps {
;
; General Orbit Traps coloring algorithm, suitable for almost
; all fractal types.
;
; Originally written by Damien M. Jones.
;
init:
; OrbitTraps and OrbitTrapsDirect are exactly the same. The DIRECT symbol
; is used to switch between the two formulas.
; don't $DEFINE DIRECT
float d = 0.0
float d2 = 0.0
complex z2 = (0,0)
int iter = 0
float diameter2 = sqr(@diameter)
complex r = (0,1) ^ (@angle / 90.0)
complex r0 = (0,0)
complex rh = (0,1) ^ (@traporder / 8); heart rotation value
complex zh = (0,0)
complex trapcenter2 = @trapcenter
if @trapshape == "ring ripples" || @trapshape == "grid ripples" || \
@trapshape == "radial ripples"
diameter2 = #pi / @diameter
endif
$IFDEF DIRECT
color accumulator = @startcolor; initialize color accumulator
color current = rgb(0,0,0); holds current iteration's color
$ELSE
float closest = 1e38
float closest1 = 1e38
complex point = (0,0)
complex point1 = (0,0)
complex point2 = (0,0)
complex point3 = (0,0)
bool done = false
int i = 0
int i1 = 0
if @traptype == "farthest" || @traptype == "sum" || \
@traptype == "average" || @traptype == "sign average" || \
@traptype == "alternating average" || @traptype == "alternating average 2" || \
@traptype == "inverted sum" || @traptype == "exponential average" || \
@traptype == "average change" || @traptype == "inverted sum squared" || \
@traptype == "trap only"
closest = 0.0
elseif @traptype == "product"
closest = 1.0
elseif @traptype == "second farthest" || @traptype == "two farthest"
closest = 0.0
closest = 0.0
endif
$ENDIF
bool usesolid = true ; assume a solid color
loop:
iter = iter + 1 ; iteration counter
$IFDEF DIRECT
z2 = #z
$ELSE
if @traptype == "trap only" ; trap only, work on unadulterated pixel
z2 = #pixel
else
z2 = #z
endif
$ENDIF
z2 = (z2 - trapcenter2) * r; rotate
if @aspect != 1.0
z2 = real(z2) + flip(imag(z2) * @aspect) ; apply aspect
endif
; determine distance from trap -- different for each shape
if @trapshape == "point"
d = cabs(z2)
elseif @trapshape == "ring"
d = abs(cabs(z2) - @diameter)
elseif @trapshape == "ring 2"
d = abs(|z2| - diameter2)
elseif @trapshape == "egg"
d = (cabs(z2-flip(@diameter)*2) + cabs(z2)*@traporder*0.5) * 0.25
elseif @trapshape == "hyperbola"
d = abs(imag(z2) * real(z2) - @diameter)
elseif @trapshape == "hypercross"
d = abs(imag(z2) * real(z2))
elseif @trapshape == "cross"
d = abs(real(z2))
d2 = abs(imag(z2))
if d2 < d
d = d2
endif
elseif @trapshape == "astroid"
d = abs(real(z2))^@traporder + abs(imag(z2))^@traporder
if @traporder < 0
d = 1/d
endif
elseif @trapshape == "diamond"
d = abs(real(z2)) + abs(imag(z2))
elseif @trapshape == "rectangle"
d = abs(real(z2))
d2 = abs(imag(z2))
if d2 > d
d = d2
endif
elseif @trapshape == "box"
d = abs(real(z2))
d2 = abs(imag(z2))
if d2 > d
d = d2
endif
d = abs(d - @diameter)
elseif @trapshape == "lines"
d = abs(abs(imag(z2)) - @diameter)
elseif @trapshape == "waves"
d = abs(abs(imag(z2) + sin(real(z2)*@trapfreq)*@traporder*0.25) - @diameter)
elseif @trapshape == "mirrored waves"
d = abs(abs(imag(z2)) - @diameter + sin(real(z2)*@trapfreq)*@traporder*0.25)
elseif @trapshape == "mirrored waves 2"
d2 = @diameter - sin(real(z2)*@trapfreq)*@traporder*0.25; compute wave height
d = abs(abs(imag(z2)) - d2); distance to each wave
d2 = abs(abs(imag(z2)) + d2)
if d2 < d
d = d2
endif
elseif @trapshape == "radial waves"
d2 = atan2(z2)
d = abs(cabs(z2) * (1 - sin(d2*@trapfreq)*@traporder*0.125) - @diameter)
elseif @trapshape == "radial waves 2"
d2 = atan2(z2)
d2 = sin(d2*@trapfreq)*@traporder*0.125
d = abs(cabs(z2) * (1 - d2) - @diameter)
d2 = abs(cabs(z2) * (1 + d2) - @diameter)
if d2 < d
d = d2
endif
elseif @trapshape == "ring ripples"
d = cabs(z2)
if d < @traporder
d = cos(d * diameter2 * @trapfreq) * sqr(1-d/@traporder)
else
d = 0
endif
elseif @trapshape == "grid ripples"
d = cabs(z2)
if d < @traporder
d = (cos(real(z2)*diameter2*@trapfreq) + cos(imag(z2)*diameter2*@trapfreq)) * sqr(1-d/@traporder) * 0.5
else
d = 0
endif
elseif @trapshape == "radial ripples"
d = atan2(z2)
d2 = cabs(z2)
if d2 < @traporder
d = cos(4 * d * @trapfreq) * sqr(1-d2/@traporder)
else
d = 0
endif
elseif @trapshape == "pinch"
d2 = atan2(z2)
if d2 < 0
d2 = d2 + 2*#pi
endif
d = sqrt(cabs(z2)) / abs(sin(d2*@traporder*0.5))
elseif @trapshape == "spiral"
d = 1/(cabs(z2)) * @diameter
r0 = (0,1) ^ d
z2 = z2 * r0
d = atan(abs(imag(z2)/real(z2)))
elseif @trapshape == "heart"
zh = real(z2) + flip(abs(imag(z2)))
zh = zh*rh * 3 / @diameter
d = abs(real(zh) - sqr(imag(zh)) + 3)
endif
$IFDEF DIRECT
; Compute direct color. This code is very similar to the normal processing
; in the final section.
IF (d < @threshold); orbit is close enough to shape
IF (@trapcolor == "distance"); distance
current = gradient(d/@threshold)
ELSEIF (@trapcolor == "magnitude"); magnitude
current = gradient(cabs(z2))
ELSEIF (@trapcolor == "real"); real
current = gradient(abs(real(z2)))
ELSEIF (@trapcolor == "imaginary"); imaginary
current = gradient(abs(imag(z2)))
ELSEIF (@trapcolor == "angle to trap"); angle to trap
d2 = atan2(z2)
IF (d2 < 0)
d2 = d2 + #pi * 2
ENDIF
current = gradient(d2 / (#pi * 2))
ELSEIF (@trapcolor == "angle to origin"); angle to origin
d2 = atan2(#z)
IF (d2 < 0)
d2 = d2 + #pi * 2
ENDIF
current = gradient(d2 / (#pi * 2))
ELSEIF (@trapcolor == "angle to origin 2") ; angle to origin 2 (old ReallyCool)
current = gradient(0.02 * abs(atan(imag(#z) / real(#z)) * 180/#pi))
ELSEIF (@trapcolor == "iteration"); iteration
current = gradient(iter / #maxiter)
ENDIF
IF (@trapmergemodifier == "distance")
current = rgba(red(current), green(current), blue(current), alpha(current) * (1 - d / @threshold))
ENDIF
IF (@trapmergeorder == "bottom-up")
accumulator = compose(accumulator, blend(current, @trapmergemode(accumulator, current), alpha(accumulator)), @trapmergeopacity)
ELSEIF (@trapmergeorder == "top-down")
accumulator = compose(current, blend(accumulator, @trapmergemode(current, accumulator), alpha(current)), @trapmergeopacity)
ENDIF
ENDIF
$ELSE
; now adjust closest/point/i as needed
IF (@traptype == 0); closest
IF (d < closest)
i = iter
point = #z
point2 = z2
closest = d
ENDIF
IF (d < @threshold)
usesolid = false
ENDIF
ELSEIF (@traptype == 1); farthest (within threshold)
IF (d > closest && d < @threshold)
i = iter
point = #z
point2 = z2
closest = d
usesolid = false
ENDIF
ELSEIF (@traptype == 2); first (within threshold)
IF (d < @threshold && done == false)
i = iter
point = #z
point2 = z2
closest = d
done = true
usesolid = false
ENDIF
ELSEIF (@traptype == 3); last (within threshold)
IF (d < @threshold)
i = iter
point = #z
point2 = z2
closest = d
done = true
usesolid = false
ENDIF
ELSEIF (@traptype == 4); sum (within threshold)
IF (d < @threshold)
i = iter
point = point + #z
point2 = point2 + z2
closest = closest + d
usesolid = false
ENDIF
ELSEIF (@traptype == 5); average (within threshold)
IF (d < @threshold)
i = iter
i1 = i1 + 1
point = point + #z
point2 = point2 + z2
closest = closest + d
usesolid = false
ENDIF
ELSEIF (@traptype == 6); product (within threshold)
IF (d < @threshold)
i = iter
point = point * #z / @threshold
point2 = point2 * z2 / @threshold
closest = closest * d / @threshold
usesolid = false
ENDIF
ELSEIF (@traptype == 7); sign average
IF (d < d2)
i = i + 1
point = point + #z
point2 = point2 + z2
closest = closest + 1
usesolid = false
ELSE
i = i - 1
ENDIF
d2 = d
ELSEIF (@traptype == 8 || @traptype == 10) ; second/two closest
IF (d < closest)
i1 = i
point1 = point
point3 = point2
closest1 = closest
i = iter
point = #z
point2 = z2
closest = d
ELSEIF (d < closest1)
i1 = iter
point1 = #z
point3 = z2
closest1 = d
ENDIF
IF (d < @threshold)
usesolid = false
ENDIF
ELSEIF (@traptype == 9 || @traptype == 11) ; second/two farthest
IF (d > closest && d < @threshold)
i1 = i
point1 = point
point3 = point2
closest1 = closest
i = iter
point = #z
point2 = z2
closest = d
usesolid = false
ELSEIF (d > closest1 && d < @threshold)
i1 = iter
point1 = #z
point3 = z2
closest1 = d
usesolid = false
ENDIF
ELSEIF (@traptype == 12); funky average
IF (d < @threshold)
i = i + 1
point = #z - point
point2 = z2 - point2
closest = @threshold - abs(closest - d)
usesolid = false
ENDIF
ELSEIF (@traptype == 13); funky average 2
IF (d < @threshold)
i = i + 1
point = #z - point
point2 = z2 - point2
closest = abs(d - @threshold + closest)
usesolid = false
ENDIF
ELSEIF (@traptype == 14); funky average 3 (Luke Plant)
IF (d < @threshold)
i = i + 1
d2 = d/@threshold
point = #z + (point-#z) * d2
point2 = z2 + (point2-z2) * d2
closest = closest + d
usesolid = false
ENDIF
ELSEIF (@traptype == 15); funky average 4 (exponential average)
IF (d < @threshold)
i = i + 1
point = #z - point
point2 = z2 - point2
closest = closest + exp(-d)
usesolid = false
ENDIF
ELSEIF (@traptype == 16); funky average 5 (average distance change)
IF (d < d2)
point = point + #z
point2 = point2 + z2
closest = closest + d2-d
usesolid = false
ENDIF
d2 = d
ELSEIF (@traptype == 17); funky average 6 (Luke Plant, 1/squared)
IF (d < @threshold)
i = i + 1
usesolid = false
ENDIF
d2 = sqr(d/@threshold)
point = #z + (point-#z) * d2
point2 = z2 + (point2-z2) * d2
closest = closest + 1/d2
ELSEIF (@traptype == 18); trap only, do first iteration
IF (iter == 1)
point = #z
point2 = z2
closest = d/@threshold
IF (d < @threshold)
usesolid = false
ENDIF
ENDIF
ENDIF
$ENDIF
final:
; Apply solid color, if it is allowed.
if @solidcolor
#solid = usesolid
else
#solid = false
endif
$IFDEF DIRECT
; Return direct color.
#color = accumulator
$ELSE
; Calculate index value.
; Un-fudge anything that was fudged.
IF (@traptype == 5); traptype average
point = point / i1
point2 = point2 / i1
closest = closest / i1
ELSEIF (@traptype == 6); traptype product
closest = abs(closest)
ELSEIF (@traptype == 7); traptype sign average
point = point / iter
point2 = point2 / iter
closest = closest / iter
ELSEIF (@traptype == 8 || @traptype == 9) ; second closest or farthest
i = i - i1
point = point - point1
point2 = point2 - point3
closest = closest - closest1
ELSEIF (@traptype == 10 || @traptype == 11) ; two closest or farthest
i = round((i + i1) / 2)
point = (point + point1) / 2
point2 = (point2 + point3) / 2
closest = (closest + closest1) / 2
ELSEIF (@traptype == 14); funky average 3
closest = @threshold * i - closest
ENDIF
; choose coloring based on method
IF (@trapcolor == 0); distance
IF (@traptype == 2 || @traptype == 3) ; first or last type