-
Notifications
You must be signed in to change notification settings - Fork 74
/
flam3.c
4163 lines (3410 loc) · 124 KB
/
flam3.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
/*
FLAM3 - cosmic recursive fractal flames
Copyright (C) 1992-2009 Spotworks LLC
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MSC_VER /* VC++ */
#define _GNU_SOURCE
#endif
#include "private.h"
#include "img.h"
#include "config.h"
#include "variations.h"
#include "interpolation.h"
#include "parser.h"
#include "filters.h"
#include "palettes.h"
#include <limits.h>
#include <locale.h>
#include <math.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#ifdef HAVE_LIBPTHREAD
#include <pthread.h>
#endif
#ifdef __APPLE__
#include <mach/mach.h>
#include <mach/mach_error.h>
#define flam3_os "OSX"
#else
#ifdef _WIN32
#define WINVER 0x0500
#include <windows.h>
#define flam3_os "WIN"
#else
#define flam3_os "LNX"
#endif
#endif
char *flam3_version() {
if (strcmp(GIT_REV, ""))
return flam3_os "-" GIT_REV;
return flam3_os "-" VERSION;
}
#define CHOOSE_XFORM_GRAIN 16384
#define CHOOSE_XFORM_GRAIN_M1 16383
#define random_distrib(v) ((v)[random()%vlen(v)])
unsigned short *flam3_create_xform_distrib(flam3_genome *cp) {
/* Xform distrib is created in this function */
int numrows;
int dist_row,i;
unsigned short *xform_distrib;
numrows = cp->num_xforms - (cp->final_xform_index>=0) + 1;
xform_distrib = calloc(numrows*CHOOSE_XFORM_GRAIN,sizeof(unsigned short));
/* First, set up the first row of the xform_distrib (raw weights) */
flam3_create_chaos_distrib(cp, -1, xform_distrib);
/* Check for non-unity chaos */
cp->chaos_enable = 1 - flam3_check_unity_chaos(cp);
if (cp->chaos_enable) {
/* Now set up a row for each of the xforms */
dist_row = 0;
for (i=0;i<cp->num_xforms;i++) {
if (cp->final_xform_index == i)
continue;
else
dist_row++;
if (flam3_create_chaos_distrib(cp, i, &(xform_distrib[CHOOSE_XFORM_GRAIN*(dist_row)]))) {
free(xform_distrib);
return(NULL);
}
}
}
return(xform_distrib);
}
/* Run this on a copy of a genome to get a strip of the output */
int flam3_make_strip(flam3_genome *cp, int nstrips, int stripnum) {
double old_center[2];
int j;
/* Strip out motion elements */
for (j=0;j<cp->num_xforms;j++)
flam3_delete_motion_elements(&cp->xform[j]);
old_center[0] = cp->center[0];
old_center[1] = cp->center[1];
cp->height /= nstrips;
cp->center[1] = cp->center[1] - ((nstrips - 1) * cp->height) / (2 * cp->pixels_per_unit * pow(2.0, cp->zoom));
cp->center[1] += cp->height * stripnum / ( cp->pixels_per_unit * pow(2.0,cp->zoom) );
rotate_by(cp->center, old_center, cp->rotate);
return(0);
}
void rotate_by(double *p, double *center, double by) {
double r[2];
double th = by * 2 * M_PI / 360.0;
double c = cos(th);
double s = -sin(th);
p[0] -= center[0];
p[1] -= center[1];
r[0] = c * p[0] - s * p[1];
r[1] = s * p[0] + c * p[1];
p[0] = r[0] + center[0];
p[1] = r[1] + center[1];
}
int flam3_check_unity_chaos(flam3_genome *cp) {
int i,j;
int num_std;
int unity=1;
num_std = cp->num_xforms - (cp->final_xform_index >= 0);
for (i=0;i<num_std;i++) {
for (j=0;j<num_std;j++) {
if ( fabs(cp->chaos[i][j]-1.0) > EPS)
unity=0;
}
}
return(unity);
}
int flam3_create_chaos_distrib(flam3_genome *cp, int xi, unsigned short *xform_distrib) {
/* Xform distrib is a preallocated array of CHOOSE_XFORM_GRAIN chars */
/* address of array is passed in, contents are modified */
double t,r,dr;
int i,j;
int num_std;
//fprintf(stdout,"storing at %ld\n",xform_distrib);
num_std = cp->num_xforms - (cp->final_xform_index >= 0);
dr = 0.0;
for (i = 0; i < num_std; i++) {
double d = cp->xform[i].density;
if (xi>=0)
d *= cp->chaos[xi][i];
//fprintf(stdout,"%f ",d);
if (d < 0.0) {
fprintf(stderr, "xform weight must be non-negative, not %g.\n", d);
return(1);
}
dr += d;
}
//fprintf(stdout,"dr=%f\n",dr);
if (dr == 0.0) {
fprintf(stderr, "cannot iterate empty flame.\n");
return(1);
}
dr = dr / CHOOSE_XFORM_GRAIN;
j = 0;
t = cp->xform[0].density;
if (xi>=0)
t *= cp->chaos[xi][0];
r = 0.0;
for (i = 0; i < CHOOSE_XFORM_GRAIN; i++) {
while (r >= t) {
j++;
if (xi>=0)
t += cp->xform[j].density*cp->chaos[xi][j];
else
t += cp->xform[j].density;
}
//fprintf(stdout,"%d ",j);
xform_distrib[i] = j;
r += dr;
}
//fprintf(stdout,"\n---\n");
return(0);
}
/*
* run the function system described by CP forward N generations. store
* the N resulting 4-vectors in SAMPLES. the initial point is passed in
* SAMPLES[0..3]. ignore the first FUSE iterations.
*/
int flam3_iterate(flam3_genome *cp, int n, int fuse, double *samples, unsigned short *xform_distrib, randctx *rc) {
int i;
double p[4], q[4];
int consec = 0;
int badvals = 0;
int lastxf=0;
int fn;
p[0] = samples[0];
p[1] = samples[1];
p[2] = samples[2];
p[3] = samples[3];
/* Perform precalculations */
for (i=0;i<cp->num_xforms;i++)
xform_precalc(cp,i);
for (i = -4*fuse; i < 4*n; i+=4) {
// fn = xform_distrib[ lastxf*CHOOSE_XFORM_GRAIN + (((unsigned)irand(rc)) % CHOOSE_XFORM_GRAIN)];
if (cp->chaos_enable)
fn = xform_distrib[ lastxf*CHOOSE_XFORM_GRAIN + (((unsigned)irand(rc)) & CHOOSE_XFORM_GRAIN_M1)];
else
fn = xform_distrib[ ((unsigned)irand(rc)) & CHOOSE_XFORM_GRAIN_M1 ];
if (apply_xform(cp, fn, p, q, rc)>0) {
consec ++;
badvals ++;
if (consec<5) {
p[0] = q[0];
p[1] = q[1];
p[2] = q[2];
p[3] = q[3];
i -= 4;
continue;
} else
consec = 0;
} else
consec = 0;
/* Store the last used transform */
lastxf = fn+1;
p[0] = q[0];
p[1] = q[1];
p[2] = q[2];
p[3] = q[3];
if (cp->final_xform_enable == 1) {
if (cp->xform[cp->final_xform_index].opacity==1 ||
flam3_random_isaac_01(rc)<cp->xform[cp->final_xform_index].opacity) {
apply_xform(cp, cp->final_xform_index, p, q, rc);
/* Keep the opacity from the original xform */
q[3] = p[3];
}
}
/* if fuse over, store it */
if (i >= 0) {
samples[i] = q[0];
samples[i+1] = q[1];
samples[i+2] = q[2];
samples[i+3] = q[3];
}
}
return(badvals);
}
int flam3_xform_preview(flam3_genome *cp, int xi, double range, int numvals, int depth, double *result, randctx *rc) {
/* We will evaluate the 'xi'th xform 'depth' times, over the following values: */
/* x in [-range : range], y in [-range : range], with 2* (2*numvals+1)^2 values returned */
double p[4];
double incr;
int outi;
int xx,yy,dd;
double oldweight;
outi=0;
oldweight = cp->xform[xi].density;
cp->xform[xi].density = 1.0;
/* Prepare the function pointers */
if (prepare_precalc_flags(cp)) {
cp->xform[xi].density = oldweight;
return(1);
}
/* Calculate increment */
incr = range / (double)numvals;
/* Perform precalculations */
xform_precalc(cp,xi);
/* Loop over the grid */
for (xx=-numvals;xx<=numvals;xx++) {
for (yy=-numvals;yy<=numvals;yy++) {
/* Calculate the input coordinates */
p[0] = (double)xx * incr;
p[1] = (double)yy * incr;
/* Loop over the depth */
for (dd=0;dd<depth;dd++)
apply_xform(cp, xi, p, p, rc);
result[outi] = p[0];
result[outi+1] = p[1];
outi += 2;
}
}
cp->xform[xi].density = oldweight;
return(0);
}
int flam3_colorhist(flam3_genome *cp, int num_batches, randctx *rc, double *hist) {
int lp,plp;
int mycolor;
unsigned short *xform_distrib;
int sbs = 10000;
double sub_batch[4*10000];
memset(hist,0,256*sizeof(double));
// get into the attractor
if (prepare_precalc_flags(cp))
return(1);
xform_distrib = flam3_create_xform_distrib(cp);
for (lp=0;lp<num_batches;lp++) {
sub_batch[0] = flam3_random_isaac_11(rc);
sub_batch[1] = flam3_random_isaac_11(rc);
sub_batch[2] = 0;
sub_batch[3] = 0;
if (xform_distrib==NULL)
return(1);
flam3_iterate(cp, sbs, 20, sub_batch, xform_distrib, rc);
// histogram the colors in the sub_batch array
for (plp=0;plp<4*sbs;plp+=4) {
mycolor = (int)(sub_batch[plp+2]*CMAP_SIZE);
if (mycolor<0) mycolor=0;
if (mycolor>CMAP_SIZE_M1) mycolor=CMAP_SIZE_M1;
hist[mycolor] += 1;
}
}
free(xform_distrib);
for (plp=0;plp<256;plp++)
hist[plp] /= (float)(num_batches*sbs);
return(0);
}
flam3_genome *sheep_loop(flam3_genome *cp, double blend) {
flam3_genome *result;
int i;
/* Allocate the genome - this must be freed by calling function */
result = calloc(1,sizeof(flam3_genome));
/* Clear it */
clear_cp(result,flam3_defaults_on);
/* Copy the original */
flam3_copy(result,cp);
/*
* Insert motion magic here :
* if there are motion elements, we will modify the contents of
* the result genome before flam3_rotate is called.
*/
for (i=0;i<cp->num_xforms;i++) {
if (cp->xform[i].num_motion>0) {
/* Apply motion parameters to result.xform[i] using blend parameter */
apply_motion_parameters(&cp->xform[i], &result->xform[i], blend);
}
/* Delete the motion parameters from the result */
flam3_delete_motion_elements(&result->xform[i]);
}
/* Rotate the affines */
flam3_rotate(result, blend*360.0,result->interpolation_type);
return(result);
}
flam3_genome *sheep_edge(flam3_genome *cp, double blend, int seqflag, double stagger) {
flam3_genome spun[2];
flam3_genome prealign[2];
flam3_genome *result;
int i,si;
char *ai;
memset(spun, 0, 2*sizeof(flam3_genome));
memset(prealign, 0, 2*sizeof(flam3_genome));
/* Allocate the memory for the result */
result = calloc(1,sizeof(flam3_genome));
/*
* Insert motion magic here :
* if there are motion elements, we will modify the contents of
* the prealign genomes before we rotate and interpolate.
*/
for (si=0;si<2;si++) {
flam3_copy(&prealign[si], &cp[si]);
for (i=0;i<cp[si].num_xforms;i++) {
if (cp[si].xform[i].num_motion>0) {
/* Apply motion parameters to result.xform[i] using blend parameter */
apply_motion_parameters(&cp[si].xform[i], &prealign[si].xform[i], blend);
}
}
}
/* Use the un-padded original for blend=0 when creating a sequence */
/* This keeps the original interpolation type intact */
if (seqflag && 0.0 == blend) {
flam3_copy(result, &prealign[0]);
} else {
/* Align what we're going to interpolate */
flam3_align(spun, prealign, 2);
spun[0].time = 0.0;
spun[1].time = 1.0;
/* Call this first to establish the asymmetric reference angles */
establish_asymmetric_refangles(spun,2);
/* Rotate the aligned xforms */
flam3_rotate(&spun[0], blend*360.0, spun[0].interpolation_type);
flam3_rotate(&spun[1], blend*360.0, spun[0].interpolation_type);
//fprintf(stderr, "xyzzy %d %d\n", spun[0].palette_interpolation, spun[1].palette_interpolation);
/* Now call the interpolation */
if (argi("unsmoother",0) == 0)
flam3_interpolate(spun, 2, smoother(blend), stagger, result);
else
flam3_interpolate(spun, 2, blend, stagger, result);
/* Interpolation type no longer needs to be forced to linear mode */
// if (!seqflag)
// result.interpolation_type = flam3_inttype_linear;
}
/* Clear the genomes we used */
clear_cp(&spun[0],flam3_defaults_on);
clear_cp(&spun[1],flam3_defaults_on);
clear_cp(&prealign[0],flam3_defaults_on);
clear_cp(&prealign[1],flam3_defaults_on);
/* Make sure there are no motion elements in the result */
for (i=0;i<result->num_xforms;i++)
flam3_delete_motion_elements(&result->xform[i]);
return(result);
}
/* BY is angle in degrees */
void flam3_rotate(flam3_genome *cp, double by, int interpolation_type) {
int i;
for (i = 0; i < cp->num_xforms; i++) {
double r[2][2];
double T[2][2];
double U[2][2];
double dtheta = by * 2.0 * M_PI / 360.0;
/* Don't rotate xforms with > 0 animate values */
if (cp->xform[i].animate == 0.0)
continue;
if (cp->xform[i].padding == 1) {
if (interpolation_type == flam3_inttype_compat) {
/* gen 202 era flam3 did not rotate padded xforms */
continue;
} else if (interpolation_type == flam3_inttype_older) {
/* not sure if 198 era flam3 rotated padded xforms */
continue;
} else if (interpolation_type == flam3_inttype_linear) {
/* don't rotate for prettier symsings */
continue;
} else if (interpolation_type == flam3_inttype_log) {
/* Current flam3: what do we prefer? */
//continue;
}
}
/* Do NOT rotate final xforms */
if (cp->final_xform_enable==1 && cp->final_xform_index==i)
continue;
r[1][1] = r[0][0] = cos(dtheta);
r[0][1] = sin(dtheta);
r[1][0] = -r[0][1];
T[0][0] = cp->xform[i].c[0][0];
T[1][0] = cp->xform[i].c[1][0];
T[0][1] = cp->xform[i].c[0][1];
T[1][1] = cp->xform[i].c[1][1];
mult_matrix(r, T, U);
cp->xform[i].c[0][0] = U[0][0];
cp->xform[i].c[1][0] = U[1][0];
cp->xform[i].c[0][1] = U[0][1];
cp->xform[i].c[1][1] = U[1][1];
}
}
#define APPMOT(x) do { addto->x += mot[i].x * motion_funcs(func,freq*blend); } while (0);
void apply_motion_parameters(flam3_xform *xf, flam3_xform *addto, double blend) {
int i,j,k;
int freq;
int func;
flam3_xform* mot;
mot = xf->motion;
/* Loop over the motion elements and add their contribution to the original vals */
for (i=0; i<xf->num_motion; i++) {
freq = mot[i].motion_freq;
func = mot[i].motion_func;
APPMOT(density); /* Must ensure > 0 after all is applied */
APPMOT(color); /* Must ensure [0,1] after all is applied */
APPMOT(opacity);
APPMOT(color_speed);
APPMOT(animate);
APPMOT(blob_low);
APPMOT(blob_high);
APPMOT(blob_waves);
APPMOT(pdj_a);
APPMOT(pdj_b);
APPMOT(pdj_c);
APPMOT(pdj_d);
APPMOT(fan2_x);
APPMOT(fan2_y);
APPMOT(rings2_val);
APPMOT(perspective_angle);
APPMOT(perspective_dist);
APPMOT(julian_power);
APPMOT(julian_dist);
APPMOT(juliascope_power);
APPMOT(juliascope_dist);
APPMOT(radial_blur_angle);
APPMOT(pie_slices);
APPMOT(pie_rotation);
APPMOT(pie_thickness);
APPMOT(ngon_sides);
APPMOT(ngon_power);
APPMOT(ngon_circle);
APPMOT(ngon_corners);
APPMOT(curl_c1);
APPMOT(curl_c2);
APPMOT(rectangles_x);
APPMOT(rectangles_y);
APPMOT(amw_amp);
APPMOT(disc2_rot);
APPMOT(disc2_twist);
APPMOT(super_shape_rnd);
APPMOT(super_shape_m);
APPMOT(super_shape_n1);
APPMOT(super_shape_n2);
APPMOT(super_shape_n3);
APPMOT(super_shape_holes);
APPMOT(flower_petals);
APPMOT(flower_holes);
APPMOT(conic_eccentricity);
APPMOT(conic_holes);
APPMOT(parabola_height);
APPMOT(parabola_width);
APPMOT(bent2_x);
APPMOT(bent2_y);
APPMOT(bipolar_shift);
APPMOT(cell_size);
APPMOT(cpow_r);
APPMOT(cpow_i);
APPMOT(cpow_power);
APPMOT(curve_xamp);
APPMOT(curve_yamp);
APPMOT(curve_xlength);
APPMOT(curve_ylength);
APPMOT(escher_beta);
APPMOT(lazysusan_x);
APPMOT(lazysusan_y);
APPMOT(lazysusan_twist);
APPMOT(lazysusan_space);
APPMOT(lazysusan_spin);
APPMOT(modulus_x);
APPMOT(modulus_y);
APPMOT(oscope_separation);
APPMOT(oscope_frequency);
APPMOT(oscope_amplitude);
APPMOT(oscope_damping);
APPMOT(popcorn2_x);
APPMOT(popcorn2_y);
APPMOT(popcorn2_c);
APPMOT(separation_x);
APPMOT(separation_xinside);
APPMOT(separation_y);
APPMOT(separation_yinside);
APPMOT(split_xsize);
APPMOT(split_ysize);
APPMOT(splits_x);
APPMOT(splits_y);
APPMOT(stripes_space);
APPMOT(stripes_warp);
APPMOT(wedge_angle);
APPMOT(wedge_hole);
APPMOT(wedge_count);
APPMOT(wedge_swirl);
APPMOT(wedge_julia_angle);
APPMOT(wedge_julia_count);
APPMOT(wedge_julia_power);
APPMOT(wedge_julia_dist);
APPMOT(wedge_sph_angle);
APPMOT(wedge_sph_hole);
APPMOT(wedge_sph_count);
APPMOT(wedge_sph_swirl);
APPMOT(whorl_inside);
APPMOT(whorl_outside);
APPMOT(waves2_scalex);
APPMOT(waves2_scaley);
APPMOT(waves2_freqx);
APPMOT(waves2_freqy);
APPMOT(auger_sym);
APPMOT(auger_weight);
APPMOT(auger_freq);
APPMOT(auger_scale);
APPMOT(flux_spread);
APPMOT(mobius_re_a);
APPMOT(mobius_re_b);
APPMOT(mobius_re_c);
APPMOT(mobius_re_d);
APPMOT(mobius_im_a);
APPMOT(mobius_im_b);
APPMOT(mobius_im_c);
APPMOT(mobius_im_d);
for (j = 0; j < flam3_nvariations; j++)
APPMOT(var[j]);
for (j=0; j<3; j++) {
for (k=0; k<2; k++) {
APPMOT(c[j][k]);
APPMOT(post[j][k]);
}
}
}
/* Make sure certain params are within reasonable bounds */
if (addto->color<0) addto->color=0;
if (addto->color>1) addto->color=1;
if (addto->density<0) addto->density=0;
}
/*
* create a control point that interpolates between the control points
* passed in CPS. CPS must be sorted by time.
*/
void flam3_interpolate(flam3_genome cps[], int ncps,
double time, double stagger, flam3_genome *result) {
int i1, i2;
double c[2];
flam3_genome cpi[4];
int smoothflag = 0;
if (1 == ncps) {
flam3_copy(result, &(cps[0]));
return;
}
if (cps[0].time >= time) {
i1 = 0;
i2 = 1;
} else if (cps[ncps - 1].time <= time) {
i1 = ncps - 2;
i2 = ncps - 1;
} else {
i1 = 0;
while (cps[i1].time < time)
i1++;
i1--;
i2 = i1 + 1;
}
c[0] = (cps[i2].time - time) / (cps[i2].time - cps[i1].time);
c[1] = 1.0 - c[0];
memset(cpi, 0, 4*sizeof(flam3_genome));
/* To interpolate the xforms, we will make copies of the source cps */
/* and ensure that they both have the same number before progressing */
if (flam3_interpolation_linear == cps[i1].interpolation) {
flam3_align(&cpi[0], &cps[i1], 2);
smoothflag = 0;
} else {
if (0 == i1) {
fprintf(stderr, "error: cannot use smooth interpolation on first segment.\n");
fprintf(stderr, "reverting to linear interpolation.\n");
flam3_align(&cpi[0], &cps[i1], 2);
smoothflag = 0;
}
if (ncps-1 == i2) {
fprintf(stderr, "error: cannot use smooth interpolation on last segment.\n");
fprintf(stderr, "reverting to linear interpolation.\n");
flam3_align(&cpi[0], &cps[i1], 2);
smoothflag = 0;
}
flam3_align(&cpi[0], &cps[i1-1], 4);
smoothflag = 1;
}
/* Clear the destination cp */
clear_cp(result, 1);
if (cpi[0].final_xform_index >= 0) {
flam3_add_xforms(result, cpi[0].num_xforms-1, 0, 0);
flam3_add_xforms(result, 1, 0, 1);
} else
flam3_add_xforms(result, cpi[0].num_xforms, 0, 0);
result->time = time;
result->interpolation = flam3_interpolation_linear;
result->interpolation_type = cpi[0].interpolation_type;
result->palette_interpolation = flam3_palette_interpolation_hsv_circular;
result->hsv_rgb_palette_blend = 0.0;
if (!smoothflag) {
flam3_interpolate_n(result, 2, cpi, c, stagger);
} else {
interpolate_catmull_rom(cpi, c[1], result);
clear_cp(&(cpi[2]),0);
clear_cp(&(cpi[3]),0);
}
clear_cp(&(cpi[0]),0);
clear_cp(&(cpi[1]),0);
}
void flam3_copy_params(flam3_xform *dest, flam3_xform *src, int varn) {
/* We only want to copy param var coefs for this one */
if (varn==VAR_BLOB) {
/* Blob */
dest->blob_low = src->blob_low;
dest->blob_high = src->blob_high;
dest->blob_waves = src->blob_waves;
} else if (varn==VAR_PDJ) {
/* PDJ */
dest->pdj_a = src->pdj_a;
dest->pdj_b = src->pdj_b;
dest->pdj_c = src->pdj_c;
dest->pdj_d = src->pdj_d;
} else if (varn==VAR_FAN2) {
/* Fan2 */
dest->fan2_x = src->fan2_x;
dest->fan2_y = src->fan2_y;
} else if (varn==VAR_RINGS2) {
/* Rings2 */
dest->rings2_val = src->rings2_val;
} else if (varn==VAR_PERSPECTIVE) {
/* Perspective */
dest->perspective_angle = src->perspective_angle;
dest->perspective_dist = src->perspective_dist;
dest->persp_vsin = src->persp_vsin;
dest->persp_vfcos = src->persp_vfcos;
} else if (varn==VAR_JULIAN) {
/* Julia_N */
dest->julian_power = src->julian_power;
dest->julian_dist = src->julian_dist;
dest->julian_rN = src->julian_rN;
dest->julian_cn = src->julian_cn;
} else if (varn==VAR_JULIASCOPE) {
/* Julia_Scope */
dest->juliascope_power = src->juliascope_power;
dest->juliascope_dist = src->juliascope_dist;
dest->juliascope_rN = src->juliascope_rN;
dest->juliascope_cn = src->juliascope_cn;
} else if (varn==VAR_RADIAL_BLUR) {
/* Radial Blur */
dest->radial_blur_angle = src->radial_blur_angle;
} else if (varn==VAR_PIE) {
/* Pie */
dest->pie_slices = src->pie_slices;
dest->pie_rotation = src->pie_rotation;
dest->pie_thickness = src->pie_thickness;
} else if (varn==VAR_NGON) {
/* Ngon */
dest->ngon_sides = src->ngon_sides;
dest->ngon_power = src->ngon_power;
dest->ngon_corners = src->ngon_corners;
dest->ngon_circle = src->ngon_circle;
} else if (varn==VAR_CURL) {
/* Curl */
dest->curl_c1 = src->curl_c1;
dest->curl_c2 = src->curl_c2;
} else if (varn==VAR_RECTANGLES) {
/* Rect */
dest->rectangles_x = src->rectangles_x;
dest->rectangles_y = src->rectangles_y;
} else if (varn==VAR_DISC2) {
/* Disc2 */
dest->disc2_rot = src->disc2_rot;
dest->disc2_twist = src->disc2_twist;
} else if (varn==VAR_SUPER_SHAPE) {
/* Supershape */
dest->super_shape_rnd = src->super_shape_rnd;
dest->super_shape_m = src->super_shape_m;
dest->super_shape_n1 = src->super_shape_n1;
dest->super_shape_n2 = src->super_shape_n2;
dest->super_shape_n3 = src->super_shape_n3;
dest->super_shape_holes = src->super_shape_holes;
} else if (varn==VAR_FLOWER) {
/* Flower */
dest->flower_petals = src->flower_petals;
dest->flower_petals = src->flower_petals;
} else if (varn==VAR_CONIC) {
/* Conic */
dest->conic_eccentricity = src->conic_eccentricity;
dest->conic_holes = src->conic_holes;
} else if (varn==VAR_PARABOLA) {
/* Parabola */
dest->parabola_height = src->parabola_height;
dest->parabola_width = src->parabola_width;
} else if (varn==VAR_BENT2) {
/* Bent2 */
dest->bent2_x = src->bent2_x;
dest->bent2_y = src->bent2_y;
} else if (varn==VAR_BIPOLAR) {
/* Bipolar */
dest->bipolar_shift = src->bipolar_shift;
} else if (varn==VAR_CELL) {
/* Cell */
dest->cell_size = src->cell_size;
} else if (varn==VAR_CPOW) {
/* Cpow */
dest->cpow_i = src->cpow_i;
dest->cpow_r = src->cpow_r;
dest->cpow_power = src->cpow_power;
} else if (varn==VAR_CURVE) {
/* Curve */
dest->curve_xamp = src->curve_xamp;
dest->curve_yamp = src->curve_yamp;
dest->curve_xlength = src->curve_xlength;
dest->curve_ylength = src->curve_ylength;
} else if (varn==VAR_ESCHER) {
/* Escher */
dest->escher_beta = src->escher_beta;
} else if (varn==VAR_LAZYSUSAN) {
/* Lazysusan */
dest->lazysusan_x = src->lazysusan_x;
dest->lazysusan_y = src->lazysusan_y;
dest->lazysusan_spin = src->lazysusan_spin;
dest->lazysusan_space = src->lazysusan_space;
dest->lazysusan_twist = src->lazysusan_twist;
} else if (varn==VAR_MODULUS) {
/* Modulus */
dest->modulus_x = src->modulus_x;
dest->modulus_y = src->modulus_y;
} else if (varn==VAR_OSCILLOSCOPE) {
/* Oscope */
dest->oscope_separation = src->oscope_separation;
dest->oscope_frequency = src->oscope_frequency;
dest->oscope_amplitude = src->oscope_amplitude;
dest->oscope_damping = src->oscope_damping;
} else if (varn==VAR_POPCORN2) {
/* Popcorn2 */
dest->popcorn2_x = src->popcorn2_x;
dest->popcorn2_y = src->popcorn2_y;
dest->popcorn2_c = src->popcorn2_c;
} else if (varn==VAR_SEPARATION) {
/* Separation */
dest->separation_x = src->separation_x;
dest->separation_y = src->separation_y;
dest->separation_xinside = src->separation_xinside;
dest->separation_yinside = src->separation_yinside;
} else if (varn==VAR_SPLIT) {
/* Split */
dest->split_xsize = src->split_xsize;
dest->split_ysize = src->split_ysize;
} else if (varn==VAR_SPLITS) {
/* Splits */
dest->splits_x = src->splits_x;
dest->splits_y = src->splits_y;
} else if (varn==VAR_STRIPES) {
/* Stripes */
dest->stripes_space = src->stripes_space;
dest->stripes_warp = src->stripes_warp;
} else if (varn==VAR_WEDGE) {
/* Wedge */
dest->wedge_angle = src->wedge_angle;
dest->wedge_hole = src->wedge_hole;
dest->wedge_count = src->wedge_count;
dest->wedge_swirl = src->wedge_swirl;
} else if (varn==VAR_WEDGE_JULIA) {
/* Wedge_Julia */
dest->wedge_julia_angle = src->wedge_julia_angle;
dest->wedge_julia_count = src->wedge_julia_count;
dest->wedge_julia_power = src->wedge_julia_power;
dest->wedge_julia_dist = src->wedge_julia_dist;
dest->wedgeJulia_cf = src->wedgeJulia_cf;
dest->wedgeJulia_cn = src->wedgeJulia_cn;
dest->wedgeJulia_rN = src->wedgeJulia_rN;
} else if (varn==VAR_WEDGE_SPH) {
/* Wedge_sph */
dest->wedge_sph_angle = src->wedge_sph_angle;
dest->wedge_sph_hole = src->wedge_sph_hole;
dest->wedge_sph_count = src->wedge_sph_count;
dest->wedge_sph_swirl = src->wedge_sph_swirl;
} else if (varn==VAR_WHORL) {
/* whorl */
dest->whorl_inside = src->whorl_inside;
dest->whorl_outside = src->whorl_outside;
} else if (varn==VAR_WAVES2) {
/* waves2 */
dest->waves2_scalex = src->waves2_scalex;
dest->waves2_scaley = src->waves2_scaley;
dest->waves2_freqx = src->waves2_freqx;
dest->waves2_freqy = src->waves2_freqy;
} else if (varn==VAR_AUGER) {
/* auger */
dest->auger_sym = src->auger_sym;
dest->auger_weight = src->auger_weight;
dest->auger_freq = src->auger_freq;
dest->auger_scale = src->auger_scale;
} else if (varn==VAR_FLUX) {
/* flux */
dest->flux_spread = src->flux_spread;
} else if (varn==VAR_MOBIUS) {
/* mobius */
dest->mobius_re_a = src->mobius_re_a;
dest->mobius_re_b = src->mobius_re_b;
dest->mobius_re_c = src->mobius_re_c;
dest->mobius_re_d = src->mobius_re_d;
dest->mobius_im_a = src->mobius_im_a;
dest->mobius_im_b = src->mobius_im_b;