📄 calcfrac.c
字号:
magnitude = sqr(new.x) + sqr(new.y);
if (magnitude < min_orbit)
{
min_orbit = magnitude;
min_index = color + 1;
}
}
if (attractors > 0) /* finite attractor in the list */
{ /* NOTE: Integer code is UNTESTED */
if (integerfractal)
{
for (i = 0; i < attractors; i++)
{
lat.x = lnew.x - lattr[i].x;
lat.x = lsqr(lat.x);
if (lat.x < l_at_rad)
{
lat.y = lnew.y - lattr[i].y;
lat.y = lsqr(lat.y);
if (lat.y < l_at_rad)
{
if ((lat.x + lat.y) < l_at_rad)
{
attracted = TRUE;
if (finattract<0) color = (color%attrperiod[i])+1;
break;
}
}
}
}
}
else
{
for (i = 0; i < attractors; i++)
{
at.x = new.x - attr[i].x;
at.x = sqr(at.x);
if (at.x < f_at_rad)
{
at.y = new.y - attr[i].y;
at.y = sqr(at.y);
if ( at.y < f_at_rad)
{
if ((at.x + at.y) < f_at_rad)
{
attracted = TRUE;
if (finattract<0) color = (color%attrperiod[i])+1;
break;
}
}
}
}
}
if (attracted)
break; /* AHA! Eaten by an attractor */
}
if (color > oldcolor) /* check periodicity */
{
if ((color & savedand) == 0) /* time to save a new value */
{
savedcolor = color;
if (!integerfractal)
saved = new; /* floating pt fractals */
else
lsaved = lnew;/* integer fractals */
if (--savedincr == 0) /* time to lengthen the periodicity? */
{
savedand = (savedand << 1) + 1; /* longer periodicity */
savedincr = 4;/* restart counter */
}
}
else /* check against an old save */
{
if (!integerfractal) /* floating-pt periodicity chk */
{
if (fabs(saved.x - new.x) < closenuff)
if (fabs(saved.y - new.y) < closenuff)
{
caught_a_cycle = 1;
cyclelen = color-savedcolor;
color = maxit - 1;
}
}
else /* integer periodicity check */
{
if (labs(lsaved.x - lnew.x) < lclosenuff)
if (labs(lsaved.y - lnew.y) < lclosenuff)
{
caught_a_cycle = 1;
cyclelen = color-savedcolor;
color = maxit - 1;
}
}
}
}
}
if (show_orbit)
scrub_orbit();
realcolor = color; /* save this before we start adjusting it */
if (color >= maxit)
oldcolor = 0; /* check periodicity immediately next time */
else
{
oldcolor = color + 10; /* check when past this + 10 next time */
if (color == 0)
color = 1; /* needed to make same as calcmand */
}
if (potflag)
{
if (integerfractal) /* adjust integer fractals */
{
new.x = ((double)lnew.x) / fudge;
new.y = ((double)lnew.y) / fudge;
}
magnitude = sqr(new.x) + sqr(new.y);
color = potential(magnitude, color);
if (LogTable)
color = LogTable[min(color, maxit)];
goto plot_pixel; /* skip any other adjustments */
}
if (color >= maxit) /* an "inside" point */
goto plot_inside; /* distest, decomp, biomorph don't apply */
if (outside < -1) /* these options by Richard Hughes modified by TW */
{
if (integerfractal)
{
new.x = ((double)lnew.x) / fudge;
new.y = ((double)lnew.y) / fudge;
}
/* Add 7 to overcome negative values on the MANDEL */
if (outside == REAL) /* "real" */
color += new.x + 7;
else if (outside == IMAG) /* "imag" */
color += new.y + 7;
else if (outside == MULT && new.y) /* "mult" */
color *= (new.x/new.y);
else if (outside == SUM) /* "sum" */
color += new.x + new.y;
/* eliminate negative colors & wrap arounds */
if (color < 0 || color > maxit)
color = 0;
}
if (distest)
{
double dist,temp;
dist = sqr(new.x) + sqr(new.y);
temp = log(dist);
dist = dist * sqr(temp) / ( sqr(deriv.x) + sqr(deriv.y) );
if (dist < dem_delta) /* point is on the edge */
{
if (distest > 0)
goto plot_inside; /* show it as an inside point */
color = 0 - distest; /* show boundary as specified color */
goto plot_pixel; /* no further adjustments apply */
}
if (colors == 2)
{
color = !inside; /* the only useful distest 2 color use */
goto plot_pixel; /* no further adjustments apply */
}
if (distest > 1) /* pick color based on distance */
{
color = sqrt(dist / dem_width + 1);
color &= INT_MAX; /* oops - color can be negative */
goto plot_pixel; /* no further adjustments apply */
}
color = dem_color; /* use pixel's "regular" color */
new = dem_new;
}
if (decomp[0] > 0)
decomposition();
else if (biomorph != -1)
{
if (integerfractal)
{
if (labs(lnew.x) < llimit2 || labs(lnew.y) < llimit2)
color = biomorph;
}
else
if (fabs(new.x) < rqlim2 || fabs(new.y) < rqlim2)
color = biomorph;
}
if (outside >= 0 && attracted == FALSE) /* merge escape-time stripes */
color = outside;
else if (LogTable)
color = LogTable[min(color, maxit)];
goto plot_pixel;
plot_inside: /* we're "inside" */
if (periodicitycheck < 0 && caught_a_cycle)
color = 7; /* show periodicity */
else if (inside >= 0)
color = inside; /* set to specified color, ignore logpal */
else
{
if(inside == STARTRAIL)
{
int i;
double diff;
color = 0;
for(i=1;i<16;i++)
{
diff = tantable[0] - tantable[i];
if(fabs(diff) < .05)
{
color = i;
break;
}
}
}
else if(inside== PERIOD) {
if (cyclelen>0) {
color = cyclelen;
} else {
color = maxit;
}
}
else if(inside == EPSCROSS)
{
if(hooper==1)
color = green;
else if(hooper==2)
color = yellow;
else
color = maxit;
if (show_orbit)
scrub_orbit();
}
else if (inside == BOF60)
color = sqrt(min_orbit) * 75;
else if (inside == BOF61)
color = min_index;
else if (inside == ZMAG)
{
if (integerfractal)
{
/*
new.x = ((double)lnew.x) / fudge;
new.y = ((double)lnew.y) / fudge;
*/
color = (((double)lsqr(lnew.x))/fudge + ((double)lsqr(lnew.y))/fudge) * (maxit>>1) + 1;
}
else
color = (sqr(new.x) + sqr(new.y)) * (maxit>>1) + 1;
}
else /* inside == -1 */
color = maxit;
if (LogTable)
color = LogTable[min(color, maxit)];
}
plot_pixel:
if (color >= colors) /* don't use color 0 unless from inside/outside */
if (colors < 16)
color &= andcolor;
else
color = ((color - 1) % andcolor) + 1; /* skip color zero */
if(debugflag != 470)
if(color <= 0 && stdcalcmode == 'b' ) /* fix BTM bug */
color = 1;
(*plot) (col, row, color);
if ((kbdcount -= realcolor) <= 0)
{
if (check_key())
return (-1);
kbdcount = max_kbdcount;
}
return (color);
}
#undef green
#undef yellow
/**************** standardfractal doodad subroutines *********************/
static void decomposition()
{
static double far cos45 = 0.70710678118654750; /* cos 45 degrees */
static double far sin45 = 0.70710678118654750; /* sin 45 degrees */
static double far cos22_5 = 0.92387953251128670; /* cos 22.5 degrees */
static double far sin22_5 = 0.38268343236508980; /* sin 22.5 degrees */
static double far cos11_25 = 0.98078528040323040; /* cos 11.25 degrees */
static double far sin11_25 = 0.19509032201612820; /* sin 11.25 degrees */
static double far cos5_625 = 0.99518472667219690; /* cos 5.625 degrees */
static double far sin5_625 = 0.09801714032956060; /* sin 5.625 degrees */
static double far tan22_5 = 0.41421356237309500; /* tan 22.5 degrees */
static double far tan11_25 = 0.19891236737965800; /* tan 11.25 degrees */
static double far tan5_625 = 0.09849140335716425; /* tan 5.625 degrees */
static double far tan2_8125 = 0.04912684976946725; /* tan 2.8125 degrees */
static double far tan1_4063 = 0.02454862210892544; /* tan 1.4063 degrees */
static long far lcos45 ; /* cos 45 degrees */
static long far lsin45 ; /* sin 45 degrees */
static long far lcos22_5 ; /* cos 22.5 degrees */
static long far lsin22_5 ; /* sin 22.5 degrees */
static long far lcos11_25 ; /* cos 11.25 degrees */
static long far lsin11_25 ; /* sin 11.25 degrees */
static long far lcos5_625 ; /* cos 5.625 degrees */
static long far lsin5_625 ; /* sin 5.625 degrees */
static long far ltan22_5 ; /* tan 22.5 degrees */
static long far ltan11_25 ; /* tan 11.25 degrees */
static long far ltan5_625 ; /* tan 5.625 degrees */
static long far ltan2_8125 ; /* tan 2.8125 degrees */
static long far ltan1_4063 ; /* tan 1.4063 degrees */
static reset_fudge = -1;
int temp = 0;
int i;
_LCMPLX lalt;
_CMPLX alt;
color = 0;
if (integerfractal) /* the only case */
{
if (reset_fudge != fudge)
{
reset_fudge = fudge;
lcos45 = cos45 *fudge;
lsin45 = sin45 *fudge;
lcos22_5 = cos22_5 *fudge;
lsin22_5 = sin22_5 *fudge;
lcos11_25 = cos11_25 *fudge;
lsin11_25 = sin11_25 *fudge;
lcos5_625 = cos5_625 *fudge;
lsin5_625 = sin5_625 *fudge;
ltan22_5 = tan22_5 *fudge;
ltan11_25 = tan11_25 *fudge;
ltan5_625 = tan5_625 *fudge;
ltan2_8125 = tan2_8125 *fudge;
ltan1_4063 = tan1_4063 *fudge;
}
if (lnew.y < 0)
{
temp = 2;
lnew.y = -lnew.y;
}
if (lnew.x < 0)
{
++temp;
lnew.x = -lnew.x;
}
if (decomp[0] >= 8)
{
temp <<= 1;
if (lnew.x < lnew.y)
{
++temp;
lalt.x = lnew.x; /* just */
lnew.x = lnew.y; /* swap */
lnew.y = lalt.x; /* them */
}
if (decomp[0] >= 16)
{
temp <<= 1;
if (multiply(lnew.x,ltan22_5,bitshift) < lnew.y)
{
++temp;
lalt = lnew;
lnew.x = multiply(lalt.x,lcos45,bitshift) +
multiply(lalt.y,lsin45,bitshift);
lnew.y = multiply(lalt.x,lsin45,bitshift) -
multiply(lalt.y,lcos45,bitshift);
}
if (decomp[0] >= 32)
{
temp <<= 1;
if (multiply(lnew.x,ltan11_25,bitshift) < lnew.y)
{
++temp;
lalt = lnew;
lnew.x = multiply(lalt.x,lcos22_5,bitshift) +
multiply(lalt.y,lsin22_5,bitshift);
lnew.y = multiply(lalt.x,lsin22_5,bitshift) -
multiply(lalt.y,lcos22_5,bitshift);
}
if (decomp[0] >= 64)
{
temp <<= 1;
if (multiply(lnew.x,ltan5_625,bitshift) < lnew.y)
{
++temp;
lalt = lnew;
lnew.x = multiply(lalt.x,lcos11_25,bitshift) +
multiply(lalt.y,lsin11_25,bitshift);
lnew.y = multiply(lalt.x,lsin11_25,bitshift) -
multiply(lalt.y,lcos11_25,bitshift);
}
if (decomp[0] >= 128)
{
temp <<= 1;
if (multiply(lnew.x,ltan2_8125,bitshift) < lnew.y)
{
++temp;
lalt = lnew;
lnew.x = multiply(lalt.x,lcos5_625,bitshift) +
multiply(lalt.y,lsin5_625,bitshift);
lnew.y = multiply(lalt.x,lsin5_625,bitshift) -
multiply(lalt.y,lcos5_625,bitshift);
}
if (decomp[0] == 256)
{
temp <<= 1;
if (multiply(lnew.x,ltan1_4063,bitshift) < lnew.y)
if ((lnew.x*ltan1_4063 < lnew.y))
++temp;
}
}
}
}
}
}
}
else /* double case */
{
if (new.y < 0)
{
temp = 2;
new.y = -new.y;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -