From b66dc836db66e9769f5c7142104c80fda6dd386b Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 2 May 2015 17:02:51 +0200 Subject: Clean up apply_xform --- flam3.c | 5 +- variations.c | 812 +++++++++++++++++++++++++++++------------------------------ variations.h | 3 +- 3 files changed, 403 insertions(+), 417 deletions(-) diff --git a/flam3.c b/flam3.c index a2bde79..74decee 100644 --- a/flam3.c +++ b/flam3.c @@ -175,7 +175,7 @@ bool iterator_step (iterator * const iter, double4 * const ret, randctx * const else fn = iter->xform_distrib[ rand_u64(rc) & CHOOSE_XFORM_GRAIN_M1 ]; - if (apply_xform(genome, fn, iter->p, &q, rc)>0) { + if (apply_xform(&genome->xform[fn], fn, iter->p, &q, rc)>0) { ++iter->consec; if (iter->consec < 5) { iter->p = q; @@ -193,7 +193,8 @@ bool iterator_step (iterator * const iter, double4 * const ret, randctx * const if (genome->final_xform_enable == 1) { if (genome->xform[genome->final_xform_index].opacity==1 || rand_d01(rc)xform[genome->final_xform_index].opacity) { - apply_xform(genome, genome->final_xform_index, iter->p, &q, rc); + apply_xform(&genome->xform[fn], genome->final_xform_index, iter->p, + &q, rc); /* Keep the opacity from the original xform */ q = (double4) { q[0], q[1], q[2], iter->p[3] }; } diff --git a/variations.c b/variations.c index e70fe17..befc0cb 100644 --- a/variations.c +++ b/variations.c @@ -16,8 +16,8 @@ */ #include "variations.h" -#include "interpolation.h" -#include "math.h" +#include "interpolation.h" +#include "math.h" #define badvalue(x) (((x)!=(x))||((x)>1e10)||((x)<-1e10)) @@ -25,12 +25,8 @@ typedef struct { double precalc_atan, precalc_sina; /* Precalculated, if needed */ double precalc_cosa, precalc_sqrt; double precalc_sumsq,precalc_atanyx; - - flam3_xform *xform; /* For the important values */ - - /* Pointer to the RNG state */ + const flam3_xform *xform; /* For the important values */ randctx *rc; - } flam3_iter_helper; char *flam3_variation_names[1+flam3_nvariations] = { @@ -185,7 +181,7 @@ static double2 var3_swirl (const double2 in, const flam3_iter_helper * const f, double r2 = f->precalc_sumsq; double c1,c2; - + sincos(r2,&c1,&c2); // double c1 = sin(r2); // double c2 = cos(r2); @@ -254,7 +250,7 @@ static double2 var7_heart (const double2 in, const flam3_iter_helper * const f, const double a = f->precalc_sqrt * f->precalc_atan; double ca,sa; const double r = weight * f->precalc_sqrt; - + sincos(a,&sa,&ca); return (double2) { r * sa, (-r) * ca }; @@ -357,7 +353,7 @@ static double2 var13_julia (const double2 in, const flam3_iter_helper * const f, a += M_PI; r = weight * sqrt(f->precalc_sqrt); - + sincos(a,&sa,&ca); return r * (double2) { ca, sa }; @@ -445,9 +441,9 @@ static double2 var18_exponential (const double2 in, const flam3_iter_helper * co double dx = weight * exp(in[0] - 1.0); double dy = M_PI * in[1]; double sdy,cdy; - + sincos(dy,&sdy,&cdy); - + return dx * (double2) { cdy, sdy }; } @@ -476,7 +472,7 @@ static double2 var20_cosine (const double2 in, const flam3_iter_helper * const f const double a = in[0] * M_PI; double sa,ca; - + sincos(a,&sa,&ca); const double2 n = (double2) { ca * cosh(in[1]), -sa * sinh(in[1]) }; @@ -607,7 +603,7 @@ static double2 var25_fan2 (const double2 in, const flam3_iter_helper * const f, a = a-dx2; else a = a+dx2; - + sincos(a,&sa,&ca); return r * (double2) { sa, ca }; @@ -681,7 +677,7 @@ static double2 var32_juliaN_generic (const double2 in, const flam3_iter_helper * /* juliaN (03/06) */ int t_rnd = trunc((f->xform->julian_rN)*rand_d01(f->rc)); - + double tmpr = (f->precalc_atanyx + 2 * M_PI * t_rnd) / f->xform->julian_power; double r = weight * pow(f->precalc_sumsq, f->xform->julian_cn); @@ -824,7 +820,7 @@ static double2 var41_arch(const double2 in, const flam3_iter_helper * const f, d FPy := FPy + sqr(sinr)/cosr*vars[29]; end; */ - + /* * !!! Note !!! * This code uses the variation weight in a non-standard fashion, and @@ -922,7 +918,7 @@ static double2 var45_blade(const double2 in, const flam3_iter_helper * const f, double r = rand_d01(f->rc) * weight * f->precalc_sqrt; double sinr,cosr; - + sincos(r,&sinr,&cosr); return weight * in[0] * (cosr + (double2) { sinr, -sinr }); @@ -969,14 +965,14 @@ static double2 var47_twintrian(const double2 in, const flam3_iter_helper * const double r = rand_d01(f->rc) * weight * f->precalc_sqrt; double sinr,cosr,diff; - + sincos(r,&sinr,&cosr); diff = log10(sinr*sinr)+cosr; - + if (badvalue(diff)) - diff = -30.0; + diff = -30.0; + - return weight * in[0] * (diff - (double2) { 0.0, sinr*M_PI }); } @@ -1048,7 +1044,7 @@ static double2 var50_supershape(const double2 in, const flam3_iter_helper * cons double myrnd; theta = f->xform->super_shape_pm_4 * f->precalc_atanyx + M_PI_4; - + sincos(theta,&st,&ct); t1 = fabs(ct); @@ -1056,10 +1052,10 @@ static double2 var50_supershape(const double2 in, const flam3_iter_helper * cons t2 = fabs(st); t2 = pow(t2,f->xform->super_shape_n3); - + myrnd = f->xform->super_shape_rnd; - r = weight * ( (myrnd*rand_d01(f->rc) + (1.0-myrnd)*f->precalc_sqrt) - f->xform->super_shape_holes) + r = weight * ( (myrnd*rand_d01(f->rc) + (1.0-myrnd)*f->precalc_sqrt) - f->xform->super_shape_holes) * pow(t1+t2,f->xform->super_shape_pneg1_n1) / f->precalc_sqrt; return r * in; @@ -1071,23 +1067,23 @@ static double2 var51_flower(const double2 in, const flam3_iter_helper * const f, r := (random-holes)*cos(petals*theta); FPx^ := FPx^ + vvar*r*cos(theta); FPy^ := FPy^ + vvar*r*sin(theta);*/ - + double theta = f->precalc_atanyx; - double r = weight * (rand_d01(f->rc) - f->xform->flower_holes) * + double r = weight * (rand_d01(f->rc) - f->xform->flower_holes) * cos(f->xform->flower_petals*theta) / f->precalc_sqrt; return r * in; } - + static double2 var52_conic(const double2 in, const flam3_iter_helper * const f, double weight) { /* cyberxaos, 4/2007 */ /* theta := arctan2(FTy^, FTx^); r := (random - holes)*((eccentricity)/(1+eccentricity*cos(theta))); FPx^ := FPx^ + vvar*r*cos(theta); FPy^ := FPy^ + vvar*r*sin(theta); */ - + double ct = in[0] / f->precalc_sqrt; - double r = weight * (rand_d01(f->rc) - f->xform->conic_holes) * + double r = weight * (rand_d01(f->rc) - f->xform->conic_holes) * f->xform->conic_eccentricity / (1 + f->xform->conic_eccentricity*ct) / f->precalc_sqrt; return r * in; @@ -1096,25 +1092,25 @@ static double2 var52_conic(const double2 in, const flam3_iter_helper * const f, static double2 var53_parabola(const double2 in, const flam3_iter_helper * const f, double weight) { /* cyberxaos, 4/2007 */ /* r := sqrt(sqr(FTx^) + sqr(FTy^)); - FPx^ := FPx^ + parabola_height*vvar*sin(r)*sin(r)*random; + FPx^ := FPx^ + parabola_height*vvar*sin(r)*sin(r)*random; FPy^ := FPy^ + parabola_width*vvar*cos(r)*random; */ - + double r = f->precalc_sqrt; double sr,cr; - + sincos(r,&sr,&cr); - + return weight * (double2) { f->xform->parabola_height * sr*sr * rand_d01(f->rc), f->xform->parabola_width * cr * rand_d01(f->rc), }; - -} + +} static double2 var54_bent2 (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Bent2 in the Apophysis Plugin Pack */ - + /* Bent2 in the Apophysis Plugin Pack */ + return weight * in * (double2) { in[0] < 0.0 ? f->xform->bent2_x : 1.0, in[1] < 0.0 ? f->xform->bent2_y : 1.0, @@ -1123,14 +1119,14 @@ static double2 var54_bent2 (const double2 in, const flam3_iter_helper * const f, static double2 var55_bipolar (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Bipolar in the Apophysis Plugin Pack */ - + /* Bipolar in the Apophysis Plugin Pack */ + double x2y2 = f->precalc_sumsq; double t = x2y2+1; double x2 = 2*in[0]; double ps = -M_PI_2 * f->xform->bipolar_shift; double y = 0.5 * atan2(2.0 * in[1], x2y2 - 1.0) + ps; - + if (y > M_PI_2) y = -M_PI_2 + fmod(y + M_PI_2, M_PI); else if (y < -M_PI_2) @@ -1144,23 +1140,23 @@ static double2 var55_bipolar (const double2 in, const flam3_iter_helper * const static double2 var56_boarders (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Boarders in the Apophysis Plugin Pack */ - + /* Boarders in the Apophysis Plugin Pack */ + double2 round = (double2) { rint(in[0]), rint(in[1]) }; double2 offset = in - round; - + if (rand_d01(f->rc) >= 0.75) { return weight*(offset*0.5 + round); } else { - + if (fabs(offset[0]) >= fabs(offset[1])) { - + if (offset[0] >= 0.0) { return weight*(offset*0.5 + round + 0.25 * (double2) { 1.0, offset[1] / offset[0] }); } else { return weight*(offset*0.5 + round - 0.25 * (double2) { 1.0, offset[1] / offset[0] }); } - + } else { if (offset[1] >= 0.0) { return weight*(offset*0.5 + round + (double2) { offset[0]/offset[1]*0.25, 0.25 }); @@ -1173,24 +1169,24 @@ static double2 var56_boarders (const double2 in, const flam3_iter_helper * const static double2 var57_butterfly (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Butterfly in the Apophysis Plugin Pack */ - + /* Butterfly in the Apophysis Plugin Pack */ + /* wx is weight*4/sqrt(3*pi) */ double wx = weight*1.3029400317411197908970256609023; - + double y2 = in[1]*2.0; double r = wx*sqrt(fabs(in[1] * in[0])/(EPS + in[0]*in[0] + y2*y2)); - + return r * (double2) { in[0], y2 }; - + } static double2 var58_cell (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Cell in the Apophysis Plugin Pack */ + /* Cell in the Apophysis Plugin Pack */ double inv_cell_size = 1.0/f->xform->cell_size; - + /* calculate input cell */ double2 b = (double2) { floor(in[0]*inv_cell_size), @@ -1199,7 +1195,7 @@ static double2 var58_cell (const double2 in, const flam3_iter_helper * const f, /* Offset from cell origin */ double2 a = in - b*f->xform->cell_size; - + /* interleave cells */ if (b[1] >= 0.0) { if (b[0] >= 0.0) { @@ -1214,13 +1210,13 @@ static double2 var58_cell (const double2 in, const flam3_iter_helper * const f, b = -(2.0*b+1.0); } } - + return weight * (a + b*f->xform->cell_size) * (double2) { 1.0, -1.0 }; } static double2 var59_cpow (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Cpow in the Apophysis Plugin Pack */ + /* Cpow in the Apophysis Plugin Pack */ double a = f->precalc_atanyx; double lnr = 0.5 * log(f->precalc_sumsq); @@ -1229,37 +1225,37 @@ static double2 var59_cpow (const double2 in, const flam3_iter_helper * const f, double vd = f->xform->cpow_i / f->xform->cpow_power; double ang = vc*a + vd*lnr + va*floor(f->xform->cpow_power*rand_d01(f->rc)); double sa,ca; - + double m = weight * exp(vc * lnr - vd * a); - + sincos(ang,&sa,&ca); - + return m * (double2) { ca, sa }; - + } static double2 var60_curve (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Curve in the Apophysis Plugin Pack */ - + /* Curve in the Apophysis Plugin Pack */ + double pc_xlen = f->xform->curve_xlength*f->xform->curve_xlength; double pc_ylen = f->xform->curve_ylength*f->xform->curve_ylength; - + if (pc_xlen<1E-20) pc_xlen = 1E-20; - + if (pc_ylen<1E-20) pc_ylen = 1E-20; return weight * (in + (double2) { f->xform->curve_xamp * exp(-in[1]*in[1]/pc_xlen), f->xform->curve_yamp * exp(-in[0]*in[0]/pc_ylen), }); - + } static double2 var61_edisc (const double2 in, const flam3_iter_helper * const f, double weight) { - /* Edisc in the Apophysis Plugin Pack */ - + /* Edisc in the Apophysis Plugin Pack */ + double tmp = f->precalc_sumsq + 1.0; double tmp2 = 2.0 * in[0]; double r1 = sqrt(tmp+tmp2); @@ -1269,16 +1265,16 @@ static double2 var61_edisc (const double2 in, const flam3_iter_helper * const f, double a2 = -acos(in[0]/xmax); double w = weight / 11.57034632; double snv,csv,snhu,cshu; - + sincos(a1,&snv,&csv); - + snhu = sinh(a2); cshu = cosh(a2); - + if (in[1] > 0.0) snv = -snv; - + return w * (double2) { cshu * csv, snhu * snv }; - + } static double2 var62_elliptic (const double2 in, const flam3_iter_helper * const f, double weight) { @@ -1292,28 +1288,28 @@ static double2 var62_elliptic (const double2 in, const flam3_iter_helper * const double b = 1.0 - a*a; double ssx = xmax - 1.0; double w = weight / M_PI_2; - + if (b<0) b = 0; else b = sqrt(b); - + if (ssx<0) ssx = 0; else ssx = sqrt(ssx); - + return w * (double2) { atan2(a,b), (in[1] > 0.0 ? 1.0 : -1.0) * log(xmax + ssx), }; - + } static double2 var63_escher (const double2 in, const flam3_iter_helper * const f, double weight) { /* Escher in the Apophysis Plugin Pack */ - + double seb,ceb; double vc,vd; double m,n; @@ -1323,15 +1319,15 @@ static double2 var63_escher (const double2 in, const flam3_iter_helper * const f double lnr = 0.5 * log(f->precalc_sumsq); sincos(f->xform->escher_beta,&seb,&ceb); - + vc = 0.5 * (1.0 + ceb); vd = 0.5 * seb; m = weight * exp(vc*lnr - vd*a); n = vc*a + vd*lnr; - + sincos(n,&sn,&cn); - + return m * (double2) { cn, sn }; } @@ -1343,43 +1339,43 @@ static double2 var64_foci (const double2 in, const flam3_iter_helper * const f, double expx = exp(in[0]) * 0.5; double expnx = 0.25 / expx; double sn,cn,tmp; - + sincos(in[1],&sn,&cn); tmp = weight/(expx + expnx - cn); - + return tmp * (double2) { expx - expnx, sn }; - + } static double2 var65_lazysusan (const double2 in, const flam3_iter_helper * const f, double weight) { /* Lazysusan in the Apophysis Plugin Pack */ - + double2 b = in + (double2) { -f->xform->lazysusan_x, f->xform->lazysusan_y }; double r = sqrt(b[0]*b[0] + b[1]*b[1]); double sina, cosa; - + if (rxform->lazysusan_spin + f->xform->lazysusan_twist*(weight-r); sincos(a,&sina,&cosa); r = weight * r; - + return r * (double2) { cosa, sina } + (double2) { f->xform->lazysusan_x, -f->xform->lazysusan_y, }; } else { - + r = weight * (1.0 + f->xform->lazysusan_space / r); - + return r * b + (double2) { f->xform->lazysusan_x, -f->xform->lazysusan_y, }; - + } - + } static double2 var66_loonie (const double2 in, const flam3_iter_helper * const f, double weight) { @@ -1391,31 +1387,31 @@ static double2 var66_loonie (const double2 in, const flam3_iter_helper * const f * This code uses the variation weight in a non-standard fashion, and * it may change or even be removed in future versions of flam3. */ - + double r2 = f->precalc_sumsq; double w2 = weight*weight; - + if (r2 < w2) { double r = weight * sqrt(w2/r2 - 1.0); return r * in; } else { return weight * in; } - + } static double2 var67_pre_blur (const double2 in, const flam3_iter_helper * const f, double weight) { /* pre-xform: PreBlur (Apo 2.08) */ - + /* Get pseudo-gaussian */ double rndG = weight * (rand_d01(f->rc) + rand_d01(f->rc) + rand_d01(f->rc) + rand_d01(f->rc) - 2.0); double rndA = rand_d01(f->rc) * 2.0 * M_PI; double sinA,cosA; - + sincos(rndA,&sinA,&cosA); - + /* Note: original coordinate changed */ return rndG * (double2) { cosA, sinA }; @@ -1424,58 +1420,58 @@ static double2 var67_pre_blur (const double2 in, const flam3_iter_helper * const static double2 var68_modulus (const double2 in, const flam3_iter_helper * const f, double weight) { /* Modulus in the Apophysis Plugin Pack */ - + double xr = 2*f->xform->modulus_x; double yr = 2*f->xform->modulus_y; double a, b; - + if (in[0] > f->xform->modulus_x) a = (-f->xform->modulus_x + fmod(in[0] + f->xform->modulus_x, xr)); else if (in[0] < -f->xform->modulus_x) a = ( f->xform->modulus_x - fmod(f->xform->modulus_x - in[0], xr)); else a = in[0]; - + if (in[1] > f->xform->modulus_y) b = (-f->xform->modulus_y + fmod(in[1] + f->xform->modulus_y, yr)); else if (in[1] < -f->xform->modulus_y) b = ( f->xform->modulus_y - fmod(f->xform->modulus_y - in[1], yr)); else b = in[1]; - + return weight * (double2) { a, b }; } static double2 var69_oscope (const double2 in, const flam3_iter_helper * const f, double weight) { /* oscilloscope from the apophysis plugin pack */ - + double tpf = 2 * M_PI * f->xform->oscope_frequency; double t; - + if (f->xform->oscope_damping == 0.0) t = f->xform->oscope_amplitude * cos(tpf*in[0]) + f->xform->oscope_separation; else { t = f->xform->oscope_amplitude * exp(-fabs(in[0])*f->xform->oscope_damping) * cos(tpf*in[0]) + f->xform->oscope_separation; } - + return (double2) { 1.0, fabs(in[1]) <= t ? -1.0 : 1.0 } * weight * in; } static double2 var70_polar2 (const double2 in, const flam3_iter_helper * const f, double weight) { /* polar2 from the apophysis plugin pack */ - + double p2v = weight / M_PI; - + return (double2) { p2v * f->precalc_atan, p2v/2.0 * log(f->precalc_sumsq) }; } static double2 var71_popcorn2 (const double2 in, const flam3_iter_helper * const f, double weight) { /* popcorn2 from the apophysis plugin pack */ - + return weight * (in + (double2) { f->xform->popcorn2_x * sin(tan(in[1]*f->xform->popcorn2_c)), f->xform->popcorn2_y * sin(tan(in[0]*f->xform->popcorn2_c)), @@ -1488,17 +1484,17 @@ static double2 var72_scry (const double2 in, const flam3_iter_helper * const f, /* scry from the apophysis plugin pack */ /* note that scry does not multiply by weight, but as the */ /* values still approach 0 as the weight approaches 0, it */ - /* should be ok */ + /* should be ok */ /* * !!! Note !!! * This code uses the variation weight in a non-standard fashion, and * it may change or even be removed in future versions of flam3. */ - + double t = f->precalc_sumsq; double r = 1.0 / (f->precalc_sqrt * (t + 1.0/(weight+EPS))); - + return r * in; } @@ -1509,7 +1505,7 @@ static double2 var73_separation (const double2 in, const flam3_iter_helper * con const double sx2 = f->xform->separation_x * f->xform->separation_x; const double sy2 = f->xform->separation_y * f->xform->separation_y; - + const double2 a = (double2) { sqrt(in[0]*in[0] + sx2), sqrt(in[1]*in[1] + sy2), @@ -1531,7 +1527,7 @@ static double2 var73_separation (const double2 in, const flam3_iter_helper * con } static double2 var74_split (const double2 in, const flam3_iter_helper * const f, double weight) { - + /* Split from apo plugins pack */ return weight * (double2) { @@ -1541,7 +1537,7 @@ static double2 var74_split (const double2 in, const flam3_iter_helper * const f, } static double2 var75_splits (const double2 in, const flam3_iter_helper * const f, double weight) { - + /* Splits from apo plugins pack */ return weight * (in + (double2) { @@ -1551,11 +1547,11 @@ static double2 var75_splits (const double2 in, const flam3_iter_helper * const f } static double2 var76_stripes (const double2 in, const flam3_iter_helper * const f, double weight) { - + /* Stripes from apo plugins pack */ double roundx,offsetx; - + roundx = floor(in[0] + 0.5); offsetx = in[0] - roundx; @@ -1567,22 +1563,22 @@ static double2 var76_stripes (const double2 in, const flam3_iter_helper * const } static double2 var77_wedge (const double2 in, const flam3_iter_helper * const f, double weight) { - + /* Wedge from apo plugins pack */ double r = f->precalc_sqrt; double a = f->precalc_atanyx + f->xform->wedge_swirl * r; double c = floor( (f->xform->wedge_count * a + M_PI)*M_1_PI*0.5); - + double comp_fac = 1 - f->xform->wedge_angle*f->xform->wedge_count*M_1_PI*0.5; double sa, ca; - + a = a * comp_fac + c * f->xform->wedge_angle; - + sincos(a,&sa,&ca); r = weight * (r + f->xform->wedge_hole); - + return r * (double2) { ca, sa }; } @@ -1596,38 +1592,38 @@ static double2 var78_wedge_julia (const double2 in, const flam3_iter_helper * co double a = (f->precalc_atanyx + 2 * M_PI * t_rnd) / f->xform->wedge_julia_power; double c = floor( (f->xform->wedge_julia_count * a + M_PI)*M_1_PI*0.5 ); double sa,ca; - + a = a * f->xform->wedgeJulia_cf + c * f->xform->wedge_julia_angle; - + sincos(a,&sa,&ca); return r * (double2) { ca, sa }; } static double2 var79_wedge_sph (const double2 in, const flam3_iter_helper * const f, double weight) { - + /* Wedge_sph from apo plugins pack */ double r = 1.0/(f->precalc_sqrt+EPS); double a = f->precalc_atanyx + f->xform->wedge_sph_swirl * r; double c = floor( (f->xform->wedge_sph_count * a + M_PI)*M_1_PI*0.5); - + double comp_fac = 1 - f->xform->wedge_sph_angle*f->xform->wedge_sph_count*M_1_PI*0.5; double sa, ca; - + a = a * comp_fac + c * f->xform->wedge_sph_angle; - sincos(a,&sa,&ca); + sincos(a,&sa,&ca); r = weight * (r + f->xform->wedge_sph_hole); - + return r * (double2) { ca, sa }; } static double2 var80_whorl (const double2 in, const flam3_iter_helper * const f, double weight) { - + /* whorl from apo plugins pack */ - + /* * !!! Note !!! * This code uses the variation weight in a non-standard fashion, and @@ -1641,17 +1637,17 @@ static double2 var80_whorl (const double2 in, const flam3_iter_helper * const f, a = f->precalc_atanyx + f->xform->whorl_inside/(weight-r); else a = f->precalc_atanyx + f->xform->whorl_outside/(weight-r); - + sincos(a,&sa,&ca); - + return weight * r * (double2) { ca, sa }; } static double2 var81_waves2 (const double2 in, const flam3_iter_helper * const f, double weight) { - + /* waves2 from Joel F */ - + return weight * (in + (double2) { f->xform->waves2_scalex*sin(in[1] * f->xform->waves2_freqx), f->xform->waves2_scaley*sin(in[0] * f->xform->waves2_freqy), @@ -1669,7 +1665,7 @@ static double2 var82_exp (const double2 in, const flam3_iter_helper * const f, d sincos(in[1],&expsin,&expcos); return weight * expe * (double2) { expcos, expsin }; } - + static double2 var83_log (const double2 in, const flam3_iter_helper * const f, double weight) { //Natural Logarithm LOG // needs precalc_atanyx and precalc_sumsq @@ -1836,7 +1832,7 @@ static double2 var98_mobius (const double2 in, const flam3_iter_helper * const f return rad_v * (double2) { (re_u*re_v + im_u*im_v), (im_u*re_v - re_u*im_v) }; } - + /* Precalc functions */ @@ -1911,7 +1907,7 @@ void xform_precalc (flam3_xform * const xform) { disc2_precalc(xform); supershape_precalc(xform); wedgeJulia_precalc(xform); -} +} static double adjust_percentage(double in) { if (in==0.0) @@ -2022,7 +2018,7 @@ int prepare_precalc_flags(flam3_genome *cp) { } else if (j==VAR_LOG) { xf->precalc_atan_yx_flag=1; } - + totnum++; } } @@ -2030,279 +2026,267 @@ int prepare_precalc_flags(flam3_genome *cp) { xf->num_active_vars = totnum; } - + return(0); } -int apply_xform(const flam3_genome * const cp, int fn, const double4 p, double4 *q_ret, randctx *rc) -{ - flam3_iter_helper f; - int var_n; - double s1; - double weight; - - f.rc = rc; - - s1 = cp->xform[fn].color_speed; - - const double2 q23 = (double2) { - s1 * cp->xform[fn].color + (1.0-s1) * p[2], - cp->xform[fn].vis_adjusted, - }; - - //fprintf(stderr,"%d : %f %f %f\n",fn,cp->xform[fn].c[0][0],cp->xform[fn].c[1][0],cp->xform[fn].c[2][0]); - - const double2 t = apply_affine ((double2) { p[0], p[1] }, cp->xform[fn].c); - - /* Pre-xforms go here, and modify the f.tx and f.ty values */ - if (cp->xform[fn].has_preblur!=0.0) - var67_pre_blur(t, &f, cp->xform[fn].has_preblur); - - /* Always calculate sumsq and sqrt */ - f.precalc_sumsq = sum(t*t); - f.precalc_sqrt = sqrt(f.precalc_sumsq); - - /* Check to see if we can precalculate any parts */ - /* Precalculate atanxy, sin, cos */ - if (cp->xform[fn].precalc_atan_xy_flag > 0) { - f.precalc_atan = atan2(t[0],t[1]); - } - - if (cp->xform[fn].precalc_angles_flag > 0) { - f.precalc_sina = t[0] / f.precalc_sqrt; - f.precalc_cosa = t[1] / f.precalc_sqrt; - } - - /* Precalc atanyx */ - if (cp->xform[fn].precalc_atan_yx_flag > 0) { - f.precalc_atanyx = atan2(t[1],t[0]); - } - - f.xform = &(cp->xform[fn]); - - double2 accum = (double2) {0.0, 0.0}; - for (var_n=0; var_n < cp->xform[fn].num_active_vars; var_n++) { - - weight = cp->xform[fn].active_var_weights[var_n]; - - switch (cp->xform[fn].varFunc[var_n]) { - - case (VAR_LINEAR): - accum += var0_linear(t, &f, weight); break; - case (VAR_SINUSOIDAL): - accum += var1_sinusoidal(t, &f, weight); break; - case (VAR_SPHERICAL): - accum += var2_spherical(t, &f, weight); break; - case (VAR_SWIRL): - accum += var3_swirl(t, &f, weight); break; - case (VAR_HORSESHOE): - accum += var4_horseshoe(t, &f, weight); break; - case (VAR_POLAR): - accum += var5_polar(t, &f, weight); break; - case (VAR_HANDKERCHIEF): - accum += var6_handkerchief(t, &f, weight); break; - case (VAR_HEART): - accum += var7_heart(t, &f, weight); break; - case (VAR_DISC): - accum += var8_disc(t, &f, weight); break; - case (VAR_SPIRAL): - accum += var9_spiral(t, &f, weight); break; - case (VAR_HYPERBOLIC): - accum += var10_hyperbolic(t, &f, weight); break; - case (VAR_DIAMOND): - accum += var11_diamond(t, &f, weight); break; - case (VAR_EX): - accum += var12_ex(t, &f, weight); break; - case (VAR_JULIA): - accum += var13_julia(t, &f, weight); break; - case (VAR_BENT): - accum += var14_bent(t, &f, weight); break; - case (VAR_WAVES): - accum += var15_waves(t, &f, weight); break; - case (VAR_FISHEYE): - accum += var16_fisheye(t, &f, weight); break; - case (VAR_POPCORN): - accum += var17_popcorn(t, &f, weight); break; - case (VAR_EXPONENTIAL): - accum += var18_exponential(t, &f, weight); break; - case (VAR_POWER): - accum += var19_power(t, &f, weight); break; - case (VAR_COSINE): - accum += var20_cosine(t, &f, weight); break; - case (VAR_RINGS): - accum += var21_rings(t, &f, weight); break; - case (VAR_FAN): - accum += var22_fan(t, &f, weight); break; - case (VAR_BLOB): - accum += var23_blob(t, &f, weight); break; - case (VAR_PDJ): - accum += var24_pdj(t, &f, weight); break; - case (VAR_FAN2): - accum += var25_fan2(t, &f, weight); break; - case (VAR_RINGS2): - accum += var26_rings2(t, &f, weight); break; - case (VAR_EYEFISH): - accum += var27_eyefish(t, &f, weight); break; - case (VAR_BUBBLE): - accum += var28_bubble(t, &f, weight); break; - case (VAR_CYLINDER): - accum += var29_cylinder(t, &f, weight); break; - case (VAR_PERSPECTIVE): - accum += var30_perspective(t, &f, weight); break; - case (VAR_NOISE): - accum += var31_noise(t, &f, weight); break; - case (VAR_JULIAN): - accum += var32_juliaN_generic(t, &f, weight); break; - case (VAR_JULIASCOPE): - accum += var33_juliaScope_generic(t, &f, weight);break; - case (VAR_BLUR): - accum += var34_blur(t, &f, weight); break; - case (VAR_GAUSSIAN_BLUR): - accum += var35_gaussian(t, &f, weight); break; - case (VAR_RADIAL_BLUR): - accum += var36_radial_blur(t, &f, weight); break; - case (VAR_PIE): - accum += var37_pie(t, &f, weight); break; - case (VAR_NGON): - accum += var38_ngon(t, &f, weight); break; - case (VAR_CURL): - accum += var39_curl(t, &f, weight); break; - case (VAR_RECTANGLES): - accum += var40_rectangles(t, &f, weight); break; - case (VAR_ARCH): - accum += var41_arch(t, &f, weight); break; - case (VAR_TANGENT): - accum += var42_tangent(t, &f, weight); break; - case (VAR_SQUARE): - accum += var43_square(t, &f, weight); break; - case (VAR_RAYS): - accum += var44_rays(t, &f, weight); break; - case (VAR_BLADE): - accum += var45_blade(t, &f, weight); break; - case (VAR_SECANT2): - accum += var46_secant2(t, &f, weight); break; - case (VAR_TWINTRIAN): - accum += var47_twintrian(t, &f, weight); break; - case (VAR_CROSS): - accum += var48_cross(t, &f, weight); break; - case (VAR_DISC2): - accum += var49_disc2(t, &f, weight); break; - case (VAR_SUPER_SHAPE): - accum += var50_supershape(t, &f, weight); break; - case (VAR_FLOWER): - accum += var51_flower(t, &f, weight); break; - case (VAR_CONIC): - accum += var52_conic(t, &f, weight); break; - case (VAR_PARABOLA): - accum += var53_parabola(t, &f, weight); break; - case (VAR_BENT2): - accum += var54_bent2(t, &f, weight); break; - case (VAR_BIPOLAR): - accum += var55_bipolar(t, &f, weight); break; - case (VAR_BOARDERS): - accum += var56_boarders(t, &f, weight); break; - case (VAR_BUTTERFLY): - accum += var57_butterfly(t, &f, weight); break; - case (VAR_CELL): - accum += var58_cell(t, &f, weight); break; - case (VAR_CPOW): - accum += var59_cpow(t, &f, weight); break; - case (VAR_CURVE): - accum += var60_curve(t, &f, weight); break; - case (VAR_EDISC): - accum += var61_edisc(t, &f, weight); break; - case (VAR_ELLIPTIC): - accum += var62_elliptic(t, &f, weight); break; - case (VAR_ESCHER): - accum += var63_escher(t, &f, weight); break; - case (VAR_FOCI): - accum += var64_foci(t, &f, weight); break; - case (VAR_LAZYSUSAN): - accum += var65_lazysusan(t, &f, weight); break; - case (VAR_LOONIE): - accum += var66_loonie(t, &f, weight); break; - case (VAR_MODULUS): - accum += var68_modulus(t, &f, weight); break; - case (VAR_OSCILLOSCOPE): - accum += var69_oscope(t, &f, weight); break; - case (VAR_POLAR2): - accum += var70_polar2(t, &f, weight); break; - case (VAR_POPCORN2): - accum += var71_popcorn2(t, &f, weight); break; - case (VAR_SCRY): - accum += var72_scry(t, &f, weight); break; - case (VAR_SEPARATION): - accum += var73_separation(t, &f, weight); break; - case (VAR_SPLIT): - accum += var74_split(t, &f, weight); break; - case (VAR_SPLITS): - accum += var75_splits(t, &f, weight); break; - case (VAR_STRIPES): - accum += var76_stripes(t, &f, weight); break; - case (VAR_WEDGE): - accum += var77_wedge(t, &f, weight); break; - case (VAR_WEDGE_JULIA): - accum += var78_wedge_julia(t, &f, weight); break; - case (VAR_WEDGE_SPH): - accum += var79_wedge_sph(t, &f, weight); break; - case (VAR_WHORL): - accum += var80_whorl(t, &f, weight); break; - case (VAR_WAVES2): - accum += var81_waves2(t, &f, weight); break; - case (VAR_EXP): - accum += var82_exp(t, &f, weight); break; - case (VAR_LOG): - accum += var83_log(t, &f, weight); break; - case (VAR_SIN): - accum += var84_sin(t, &f, weight); break; - case (VAR_COS): - accum += var85_cos(t, &f, weight); break; - case (VAR_TAN): - accum += var86_tan(t, &f, weight); break; - case (VAR_SEC): - accum += var87_sec(t, &f, weight); break; - case (VAR_CSC): - accum += var88_csc(t, &f, weight); break; - case (VAR_COT): - accum += var89_cot(t, &f, weight); break; - case (VAR_SINH): - accum += var90_sinh(t, &f, weight); break; - case (VAR_COSH): - accum += var91_cosh(t, &f, weight); break; - case (VAR_TANH): - accum += var92_tanh(t, &f, weight); break; - case (VAR_SECH): - accum += var93_sech(t, &f, weight); break; - case (VAR_CSCH): - accum += var94_csch(t, &f, weight); break; - case (VAR_COTH): - accum += var95_coth(t, &f, weight); break; - case (VAR_AUGER): - accum += var96_auger(t, &f, weight); break; - case (VAR_FLUX): - accum += var97_flux(t, &f, weight); break; - case (VAR_MOBIUS): - accum += var98_mobius(t, &f, weight); break; - } - - } - double2 q01; - /* apply the post transform */ - if (cp->xform[fn].has_post) { - q01 = apply_affine (accum, cp->xform[fn].post); - } else { - q01 = accum; - } - - /* Check for badvalues and return randoms if bad */ - if (badvalue(q01[0]) || badvalue(q01[1])) { - *q_ret = (double4) { rand_d11(rc), rand_d11(rc), q23[0], q23[1] }; - return(1); - } else { - *q_ret = (double4) { q01[0], q01[1], q23[0], q23[1] }; - return(0); - } - +int apply_xform(const flam3_xform * const xf, const unsigned int fn, + const double4 p, double4 *q_ret, randctx * const rc) { + flam3_iter_helper f = { .rc = rc, .xform = xf }; + + const double s1 = xf->color_speed; + + const double2 q23 = (double2) { + s1 * xf->color + (1.0-s1) * p[2], + xf->vis_adjusted, + }; + + const double2 t = apply_affine ((double2) { p[0], p[1] }, xf->c); + + /* Pre-xforms go here, and modify the f.tx and f.ty values */ + if (xf->has_preblur!=0.0) + var67_pre_blur(t, &f, xf->has_preblur); + + /* Always calculate sumsq and sqrt */ + f.precalc_sumsq = sum(t*t); + f.precalc_sqrt = sqrt(f.precalc_sumsq); + + /* Check to see if we can precalculate any parts */ + /* Precalculate atanxy, sin, cos */ + if (xf->precalc_atan_xy_flag > 0) { + f.precalc_atan = atan2(t[0],t[1]); + } + + if (xf->precalc_angles_flag > 0) { + f.precalc_sina = t[0] / f.precalc_sqrt; + f.precalc_cosa = t[1] / f.precalc_sqrt; + } + + /* Precalc atanyx */ + if (xf->precalc_atan_yx_flag > 0) { + f.precalc_atanyx = atan2(t[1],t[0]); + } + + double2 accum = (double2) {0.0, 0.0}; + for (unsigned int var_n=0; var_n < xf->num_active_vars; var_n++) { + const double weight = xf->active_var_weights[var_n]; + + switch (xf->varFunc[var_n]) { + case (VAR_LINEAR): + accum += var0_linear(t, &f, weight); break; + case (VAR_SINUSOIDAL): + accum += var1_sinusoidal(t, &f, weight); break; + case (VAR_SPHERICAL): + accum += var2_spherical(t, &f, weight); break; + case (VAR_SWIRL): + accum += var3_swirl(t, &f, weight); break; + case (VAR_HORSESHOE): + accum += var4_horseshoe(t, &f, weight); break; + case (VAR_POLAR): + accum += var5_polar(t, &f, weight); break; + case (VAR_HANDKERCHIEF): + accum += var6_handkerchief(t, &f, weight); break; + case (VAR_HEART): + accum += var7_heart(t, &f, weight); break; + case (VAR_DISC): + accum += var8_disc(t, &f, weight); break; + case (VAR_SPIRAL): + accum += var9_spiral(t, &f, weight); break; + case (VAR_HYPERBOLIC): + accum += var10_hyperbolic(t, &f, weight); break; + case (VAR_DIAMOND): + accum += var11_diamond(t, &f, weight); break; + case (VAR_EX): + accum += var12_ex(t, &f, weight); break; + case (VAR_JULIA): + accum += var13_julia(t, &f, weight); break; + case (VAR_BENT): + accum += var14_bent(t, &f, weight); break; + case (VAR_WAVES): + accum += var15_waves(t, &f, weight); break; + case (VAR_FISHEYE): + accum += var16_fisheye(t, &f, weight); break; + case (VAR_POPCORN): + accum += var17_popcorn(t, &f, weight); break; + case (VAR_EXPONENTIAL): + accum += var18_exponential(t, &f, weight); break; + case (VAR_POWER): + accum += var19_power(t, &f, weight); break; + case (VAR_COSINE): + accum += var20_cosine(t, &f, weight); break; + case (VAR_RINGS): + accum += var21_rings(t, &f, weight); break; + case (VAR_FAN): + accum += var22_fan(t, &f, weight); break; + case (VAR_BLOB): + accum += var23_blob(t, &f, weight); break; + case (VAR_PDJ): + accum += var24_pdj(t, &f, weight); break; + case (VAR_FAN2): + accum += var25_fan2(t, &f, weight); break; + case (VAR_RINGS2): + accum += var26_rings2(t, &f, weight); break; + case (VAR_EYEFISH): + accum += var27_eyefish(t, &f, weight); break; + case (VAR_BUBBLE): + accum += var28_bubble(t, &f, weight); break; + case (VAR_CYLINDER): + accum += var29_cylinder(t, &f, weight); break; + case (VAR_PERSPECTIVE): + accum += var30_perspective(t, &f, weight); break; + case (VAR_NOISE): + accum += var31_noise(t, &f, weight); break; + case (VAR_JULIAN): + accum += var32_juliaN_generic(t, &f, weight); break; + case (VAR_JULIASCOPE): + accum += var33_juliaScope_generic(t, &f, weight);break; + case (VAR_BLUR): + accum += var34_blur(t, &f, weight); break; + case (VAR_GAUSSIAN_BLUR): + accum += var35_gaussian(t, &f, weight); break; + case (VAR_RADIAL_BLUR): + accum += var36_radial_blur(t, &f, weight); break; + case (VAR_PIE): + accum += var37_pie(t, &f, weight); break; + case (VAR_NGON): + accum += var38_ngon(t, &f, weight); break; + case (VAR_CURL): + accum += var39_curl(t, &f, weight); break; + case (VAR_RECTANGLES): + accum += var40_rectangles(t, &f, weight); break; + case (VAR_ARCH): + accum += var41_arch(t, &f, weight); break; + case (VAR_TANGENT): + accum += var42_tangent(t, &f, weight); break; + case (VAR_SQUARE): + accum += var43_square(t, &f, weight); break; + case (VAR_RAYS): + accum += var44_rays(t, &f, weight); break; + case (VAR_BLADE): + accum += var45_blade(t, &f, weight); break; + case (VAR_SECANT2): + accum += var46_secant2(t, &f, weight); break; + case (VAR_TWINTRIAN): + accum += var47_twintrian(t, &f, weight); break; + case (VAR_CROSS): + accum += var48_cross(t, &f, weight); break; + case (VAR_DISC2): + accum += var49_disc2(t, &f, weight); break; + case (VAR_SUPER_SHAPE): + accum += var50_supershape(t, &f, weight); break; + case (VAR_FLOWER): + accum += var51_flower(t, &f, weight); break; + case (VAR_CONIC): + accum += var52_conic(t, &f, weight); break; + case (VAR_PARABOLA): + accum += var53_parabola(t, &f, weight); break; + case (VAR_BENT2): + accum += var54_bent2(t, &f, weight); break; + case (VAR_BIPOLAR): + accum += var55_bipolar(t, &f, weight); break; + case (VAR_BOARDERS): + accum += var56_boarders(t, &f, weight); break; + case (VAR_BUTTERFLY): + accum += var57_butterfly(t, &f, weight); break; + case (VAR_CELL): + accum += var58_cell(t, &f, weight); break; + case (VAR_CPOW): + accum += var59_cpow(t, &f, weight); break; + case (VAR_CURVE): + accum += var60_curve(t, &f, weight); break; + case (VAR_EDISC): + accum += var61_edisc(t, &f, weight); break; + case (VAR_ELLIPTIC): + accum += var62_elliptic(t, &f, weight); break; + case (VAR_ESCHER): + accum += var63_escher(t, &f, weight); break; + case (VAR_FOCI): + accum += var64_foci(t, &f, weight); break; + case (VAR_LAZYSUSAN): + accum += var65_lazysusan(t, &f, weight); break; + case (VAR_LOONIE): + accum += var66_loonie(t, &f, weight); break; + case (VAR_MODULUS): + accum += var68_modulus(t, &f, weight); break; + case (VAR_OSCILLOSCOPE): + accum += var69_oscope(t, &f, weight); break; + case (VAR_POLAR2): + accum += var70_polar2(t, &f, weight); break; + case (VAR_POPCORN2): + accum += var71_popcorn2(t, &f, weight); break; + case (VAR_SCRY): + accum += var72_scry(t, &f, weight); break; + case (VAR_SEPARATION): + accum += var73_separation(t, &f, weight); break; + case (VAR_SPLIT): + accum += var74_split(t, &f, weight); break; + case (VAR_SPLITS): + accum += var75_splits(t, &f, weight); break; + case (VAR_STRIPES): + accum += var76_stripes(t, &f, weight); break; + case (VAR_WEDGE): + accum += var77_wedge(t, &f, weight); break; + case (VAR_WEDGE_JULIA): + accum += var78_wedge_julia(t, &f, weight); break; + case (VAR_WEDGE_SPH): + accum += var79_wedge_sph(t, &f, weight); break; + case (VAR_WHORL): + accum += var80_whorl(t, &f, weight); break; + case (VAR_WAVES2): + accum += var81_waves2(t, &f, weight); break; + case (VAR_EXP): + accum += var82_exp(t, &f, weight); break; + case (VAR_LOG): + accum += var83_log(t, &f, weight); break; + case (VAR_SIN): + accum += var84_sin(t, &f, weight); break; + case (VAR_COS): + accum += var85_cos(t, &f, weight); break; + case (VAR_TAN): + accum += var86_tan(t, &f, weight); break; + case (VAR_SEC): + accum += var87_sec(t, &f, weight); break; + case (VAR_CSC): + accum += var88_csc(t, &f, weight); break; + case (VAR_COT): + accum += var89_cot(t, &f, weight); break; + case (VAR_SINH): + accum += var90_sinh(t, &f, weight); break; + case (VAR_COSH): + accum += var91_cosh(t, &f, weight); break; + case (VAR_TANH): + accum += var92_tanh(t, &f, weight); break; + case (VAR_SECH): + accum += var93_sech(t, &f, weight); break; + case (VAR_CSCH): + accum += var94_csch(t, &f, weight); break; + case (VAR_COTH): + accum += var95_coth(t, &f, weight); break; + case (VAR_AUGER): + accum += var96_auger(t, &f, weight); break; + case (VAR_FLUX): + accum += var97_flux(t, &f, weight); break; + case (VAR_MOBIUS): + accum += var98_mobius(t, &f, weight); break; + } + + } + double2 q01; + /* apply the post transform */ + if (xf->has_post) { + q01 = apply_affine (accum, xf->post); + } else { + q01 = accum; + } + + /* Check for badvalues and return randoms if bad */ + if (badvalue(q01[0]) || badvalue(q01[1])) { + *q_ret = (double4) { rand_d11(rc), rand_d11(rc), q23[0], q23[1] }; + return 1; + } else { + *q_ret = (double4) { q01[0], q01[1], q23[0], q23[1] }; + return 0; + } } void initialize_xforms(flam3_genome *thiscp, int start_here) { @@ -2412,19 +2396,19 @@ void initialize_xforms(flam3_genome *thiscp, int start_here) { thiscp->xform[i].wedgeJulia_rN = 1.0; thiscp->xform[i].whorl_inside = 0.0; thiscp->xform[i].whorl_outside = 0.0; - - thiscp->xform[i].waves2_scalex = 0.0; - thiscp->xform[i].waves2_scaley = 0.0; - thiscp->xform[i].waves2_freqx = 0.0; - thiscp->xform[i].waves2_freqy = 0.0; - + + thiscp->xform[i].waves2_scalex = 0.0; + thiscp->xform[i].waves2_scaley = 0.0; + thiscp->xform[i].waves2_freqx = 0.0; + thiscp->xform[i].waves2_freqy = 0.0; + thiscp->xform[i].auger_freq = 1.0; thiscp->xform[i].auger_weight = 0.5; thiscp->xform[i].auger_sym = 0.0; - thiscp->xform[i].auger_scale = 1.0; + thiscp->xform[i].auger_scale = 1.0; thiscp->xform[i].flux_spread = 0.0; - + thiscp->xform[i].julian_power = 1.0; thiscp->xform[i].julian_dist = 1.0; thiscp->xform[i].julian_rN = 1.0; diff --git a/variations.h b/variations.h index 5d9f2bd..1aa7a7a 100644 --- a/variations.h +++ b/variations.h @@ -22,6 +22,7 @@ void xform_precalc (flam3_xform * const xform); int prepare_precalc_flags(flam3_genome *); -int apply_xform(const flam3_genome * const cp, int fn, const double4 p, double4 *q_ret, randctx *rc); +int apply_xform(const flam3_xform * const xf, const unsigned int fn, + const double4 p, double4 *q_ret, randctx * const rc); void initialize_xforms(flam3_genome *thiscp, int start_here); -- cgit v1.2.3