📄 miscfrac.c
字号:
param[3] += iystop + 1;
start_row = -1; /* after 1st iteration its = 0 */
}
else {
if(rflag || randparam==0 || randparam==-1){
for (col=0;col<=ixstop;col++) {
cell_array[filled][col] = rand15()%k;
}
} /* end of if random */
else {
for (col=0;col<=ixstop;col++) { /* Clear from end to end */
cell_array[filled][col] = 0;
}
i = 0;
for (col=(ixstop-16)/2;col<(ixstop+16)/2;col++) { /* insert initial */
cell_array[filled][col] = init_string[i++]; /* string */
}
} /* end of if not random */
if (lnnmbr != 0)
lstscreenflag = 1;
else
lstscreenflag = 0;
put_line(start_row,0,ixstop,cell_array[filled]);
}
start_row++;
/* This section calculates the starting line when it is not zero */
/* This section can't be resumed since no screen output is generated */
/* calculates the (lnnmbr - 1) generation */
if (lstscreenflag) { /* line number != 0 & not resuming & not continuing */
for (row = start_row; row < lnnmbr; row++) {
thinking(1,"Cellular thinking (higher start row takes longer)");
if(rflag || randparam==0 || randparam==-1){
/* Use a random border */
for (i=0;i<=r;i++) {
cell_array[notfilled][i]=rand15()%k;
cell_array[notfilled][ixstop-i]=rand15()%k;
}
}
else {
/* Use a zero border */
for (i=0;i<=r;i++) {
cell_array[notfilled][i]=0;
cell_array[notfilled][ixstop-i]=0;
}
}
t = 0; /* do first cell */
for (i=0;i<=r+r;i++)
t += cell_array[filled][i];
if (t>rule_digits || t<0) {
thinking(0, NULL);
abort_cellular(BAD_T, t);
return(-1);
}
cell_array[notfilled][r] = cell_table[t];
/* use a rolling sum in t */
for (col=r+1;col<ixstop-r;col++) { /* now do the rest */
t = t + cell_array[filled][col+r] - cell_array[filled][col-r-1];
if (t>rule_digits || t<0) {
thinking(0, NULL);
abort_cellular(BAD_T, t);
return(-1);
}
cell_array[notfilled][col] = cell_table[t];
}
filled = notfilled;
notfilled = 1-filled;
if (check_key()) {
thinking(0, NULL);
abort_cellular(CELLULAR_DONE, 0);
alloc_resume(10,1);
put_resume(sizeof(int),&row,0);
return -1;
}
}
start_row = 0;
thinking(0, NULL);
lstscreenflag = 0;
}
/* This section does all the work */
contloop:
for (row = start_row; row <= iystop; row++) {
if(rflag || randparam==0 || randparam==-1){
/* Use a random border */
for (i=0;i<=r;i++) {
cell_array[notfilled][i]=rand15()%k;
cell_array[notfilled][ixstop-i]=rand15()%k;
}
}
else {
/* Use a zero border */
for (i=0;i<=r;i++) {
cell_array[notfilled][i]=0;
cell_array[notfilled][ixstop-i]=0;
}
}
t = 0; /* do first cell */
for (i=0;i<=r+r;i++)
t += cell_array[filled][i];
if (t>rule_digits || t<0) {
thinking(0, NULL);
abort_cellular(BAD_T, t);
return(-1);
}
cell_array[notfilled][r] = cell_table[t];
/* use a rolling sum in t */
for (col=r+1;col<ixstop-r;col++) { /* now do the rest */
t = t + cell_array[filled][col+r] - cell_array[filled][col-r-1];
if (t>rule_digits || t<0) {
thinking(0, NULL);
abort_cellular(BAD_T, t);
return(-1);
}
cell_array[notfilled][col] = cell_table[t];
}
filled = notfilled;
notfilled = 1-filled;
put_line(row,0,ixstop,cell_array[filled]);
if (check_key()) {
abort_cellular(CELLULAR_DONE, 0);
alloc_resume(10,1);
put_resume(sizeof(int),&row,0);
return -1;
}
}
if(nxtscreenflag) {
param[3] += iystop + 1;
start_row = -1; /* after 1st iteration its = 0 */
goto contloop;
}
abort_cellular(CELLULAR_DONE, 0);
return 1;
}
int CellularSetup(void)
{
if (!resuming) {
nxtscreenflag = 0; /* initialize flag */
}
timer(0,curfractalspecific->calctype);
return(0);
}
static void set_Cellular_palette()
{
extern char far *mapdacbox;
static Palettetype Red = {
42, 0, 0 };
static Palettetype Green = {
10,35,10 };
static Palettetype Blue = {
13,12,29 };
static Palettetype Yellow = {
60,58,18 };
static Palettetype Brown = {
42,21, 0 };
int i;
if (mapdacbox) return; /* map= specified */
dacbox[0].red = 0 ;
dacbox[0].green= 0 ;
dacbox[0].blue = 0 ;
dacbox[1].red = Red.red;
dacbox[1].green = Red.green;
dacbox[1].blue = Red.blue;
dacbox[2].red = Green.red;
dacbox[2].green = Green.green;
dacbox[2].blue = Green.blue;
dacbox[3].red = Blue.red;
dacbox[3].green = Blue.green;
dacbox[3].blue = Blue.blue;
dacbox[4].red = Yellow.red;
dacbox[4].green = Yellow.green;
dacbox[4].blue = Yellow.blue;
dacbox[5].red = Brown.red;
dacbox[5].green = Brown.green;
dacbox[5].blue = Brown.blue;
SetTgaColors();
spindac(0,1);
}
/* frothy basin routines */
static char froth3_256c[] = "froth3.map";
static char froth6_256c[] = "froth6.map";
static char froth3_16c[] = "froth316.map";
static char froth6_16c[] = "froth616.map";
int frothsix=0;
int froth_altcolor;
int froth_shades;
extern int colorstate;
/* color maps which attempt to replicate the images of James Alexander. */
static void set_Froth_palette(void)
{
char *mapname;
if (colorstate != 0) /* 0 means dacbox matches default */
return;
if (colors >= 16)
{
if (colors >= 256)
{
if (frothsix)
mapname = froth6_256c;
else
mapname = froth3_256c;
}
else /* colors >= 16 */
{
if (frothsix)
mapname = froth6_16c;
else
mapname = froth3_16c;
}
if (ValidateLuts(mapname) != 0)
return;
colorstate = 0; /* treat map it as default */
spindac(0,1);
}
}
int froth_setup(void)
{
if (param[0] != 3 && param[0] != 6) /* if no match then*/
param[0] = 3; /* make it 3 */
frothsix = param[0] == 6;
froth_altcolor = param[1] != 0;
froth_shades = (colors-1) / (frothsix ? 6 : 3);
/* rqlim needs to be at least 6 or so */
if (rqlim < 6.0)
rqlim=6.0;
set_Froth_palette();
/* make the best of the .map situation */
orbit_color = !frothsix && colors >= 16 ? (froth_shades<<1)+1 : colors-1;
return 1;
}
/* Froth Fractal type */
int calcfroth(void) /* per pixel 1/2/g, called with row & col set */
{
int found_attractor=0;
double x, y, nx, ny, x2, y2;
long lx, ly, lnx, lny, lx2, ly2;
/* These points were determined imperically and verified experimentally */
/* using the program WL-Plot, a plotting program which has a mode for */
/* orbits of recursive relations. */
#define CLOSE 1e-6 /* seems like a good value */
#define SQRT3 1.732050807568877193
#define A 1.02871376822
#define B1 (A/2)
#define M2 SQRT3
#define B2 (-A)
#define M3 (-SQRT3)
#define B3 (-A)
#define X1MIN -1.04368901270
#define X1MAX 1.33928675524
#define XMIDT -0.339286755220
#define X2MAX1 0.96729063460
#define XMIDR 0.61508950585
#define X3MIN1 -0.22419724936
#define X2MIN2 -1.11508950586
#define XMIDL -0.27580275066
#define X3MAX2 0.07639837810
#define FROTH_BITSHIFT 28
/* compiler should handle this at compile time */
#define D_TO_L(x) ((long)((x)*(1L<<FROTH_BITSHIFT)))
orbit_ptr = 0;
color = 0;
if(showdot>0)
(*plot) (col, row, showdot&(colors-1));
if (!integerfractal) /* fp mode */
{
double close= CLOSE;
double a= A;
double b1= B1;
double xmidt= XMIDT;
double m2= M2;
double b2= B2;
double m3= M3;
double b3= B3;
double x1min= X1MIN;
double x1max= X1MAX;
double x2max1= X2MAX1;
double xmidr= XMIDR;
double x3min1= X3MIN1;
double x2min2= X2MIN2;
double xmidl= XMIDL;
double x3max2= X3MAX2;
if(invert)
{
invertz2(&tmp);
x = tmp.x;
y = tmp.y;
}
else
{
x = dx0[col]+dx1[row];
y = dy0[row]+dy1[col];
}
magnitude = (x2=sqr(x)) + (y2=sqr(y));
while (!found_attractor && (magnitude < rqlim) && (color < maxit))
{
/* simple formula: z = z^2 + conj(z*(-1+ai)) */
/* but it's the attractor that makes this so interesting */
nx = x2 - y2 - x - a*y;
ny = (x+x)*y - a*x + y;
x = nx;
y = ny;
if (frothsix) /* repeat mapping */
{
nx = sqr(x) - sqr(y) - x - a*y;
ny = (x+x)*y - a*x + y;
x = nx;
y = ny;
}
magnitude = (x2=sqr(x)) + (y2=sqr(y));
color++;
if (show_orbit)
plot_orbit(x, y, -1);
if (x > x1min && x < x1max && fabs(b1-y) < close)
{
if (!frothsix || x < xmidt)
found_attractor = 1;
else
found_attractor = 2;
}
else if (fabs(m2*x+b2-y) < close)
{
if (x > xmidr && x < x2max1)
found_attractor = !frothsix ? 2 : 4;
else if (x > x3min1 && x < xmidr)
found_attractor = !frothsix ? 3 : 6;
}
else if (fabs(m3*x+b3-y) < close)
{
if (x > x2min2 && x < xmidl)
found_attractor = !frothsix ? 2 : 3;
else if (x > xmidl && x < x3max2)
found_attractor = !frothsix ? 3 : 5;
}
}
}
else /* integer mode */
{
long lclose= D_TO_L(CLOSE);
long la= D_TO_L(A);
long lb1= D_TO_L(B1);
long lxmidt= D_TO_L(XMIDT);
long lm2= D_TO_L(M2);
long lb2= D_TO_L(B2);
long lm3= D_TO_L(M3);
long lb3= D_TO_L(B3);
long lx1min= D_TO_L(X1MIN);
long lx1max= D_TO_L(X1MAX);
long lx2max1= D_TO_L(X2MAX1);
long lxmidr= D_TO_L(XMIDR);
long lx3min1= D_TO_L(X3MIN1);
long lx2min2= D_TO_L(X2MIN2);
long lxmidl= D_TO_L(XMIDL);
long lx3max2= D_TO_L(X3MAX2);
if(invert)
{
invertz2(&tmp);
lx = tmp.x * fudge;
ly = tmp.y * fudge;
}
else
{
lx = lx0[col] + lx1[row];
ly = ly0[row] + ly1[col];
}
lmagnitud = (lx2=lsqr(lx)) + (ly2=lsqr(ly));
while (!found_attractor && (lmagnitud < llimit)
&& (lmagnitud > 0) && (color < maxit))
{
/* simple formula: z = z^2 + conj(z*(-1+ai)) */
/* but it's the attractor that makes this so interesting */
lnx = lx2 - ly2 - lx - multiply(la,ly,bitshift);
lny = (multiply(lx,ly,bitshift)<<1) - multiply(la,lx,bitshift) + ly;
lx = lnx;
ly = lny;
if (frothsix)
{
lmagnitud = (lx2=lsqr(lx)) + (ly2=lsqr(ly));
if ((lmagnitud > llimit) || (lmagnitud < 0))
break;
lnx = lx2 - ly2 - lx - multiply(la,ly,bitshift);
lny = (multiply(lx,ly,bitshift)<<1) - multiply(la,lx,bitshift) + ly;
lx = lnx;
ly = lny;
}
lmagnitud = (lx2=lsqr(lx)) + (ly2=lsqr(ly));
color++;
if (show_orbit)
iplot_orbit(lx, ly, -1);
if (lx > lx1min && lx < lx1max && labs(lb1-ly) < lclose)
{
if (!frothsix || lx < lxmidt)
found_attractor = 1;
else
found_attractor = 2;
}
else if (labs(multiply(lm2,lx,bitshift)+lb2-ly) < lclose)
{
if (lx > lxmidr && lx < lx2max1)
found_attractor = !frothsix ? 2 : 4;
else if (lx > lx3min1 && lx < lxmidr)
found_attractor = !frothsix ? 3 : 6;
}
else if (labs(multiply(lm3,lx,bitshift)+lb3-ly) < lclose)
{
if (lx > lx2min2 && lx < lxmidl)
found_attractor = !frothsix ? 2 : 3;
else if (lx > lxmidl && lx < lx3max2)
found_attractor = !frothsix ? 3 : 5;
}
}
}
if (show_orbit)
scrub_orbit();
realcolor = color;
if ((kbdcount -= realcolor) <= 0)
{
if (check_key())
return (-1);
kbdcount = max_kbdcount;
}
/* inside - Here's where non-palette based images would be nice. Instead, */
/* we'll use blocks of (colors-1)/3 or (colors-1)/6 and use special froth */
/* color maps in attempt to replicate the images of James Alexander. */
if (found_attractor)
{
if (colors >= 256)
{
if (!froth_altcolor)
{
if (color > froth_shades)
color = froth_shades;
}
else
color = froth_shades * color / maxit;
if (color == 0)
color = 1;
color += froth_shades * (found_attractor-1);
}
else if (colors >= 16)
{ /* only alternate coloring scheme available for 16 colors */
long lshade;
/* Trying to make a better 16 color distribution. */
/* Since their are only a few possiblities, just handle each case. */
/* This is a mostly guess work here. */
lshade = ((long)color<<16)/maxit;
if (!frothsix)
{
if (lshade < 2622) /* 0.04 */
color = 1;
else if (lshade < 10486) /* 0.16 */
color = 2;
else if (lshade < 23593) /* 0.36 */
color = 3;
else if (lshade < 41943) /* 0.64 */
color = 4;
else
color = 5;
color += 5 * (found_attractor-1);
}
else
{
if (lshade < 10486) /* 0.16 */
color = 1;
else
color = 2;
color += 2 * (found_attractor-1);
}
}
else /* use a color corresponding to the attractor */
color = found_attractor;
oldcolor = color;
}
else if (color >= maxit)
color = oldcolor; /* inside, but didn't get sucked in by attractor. */
else /* outside */
color = 0; /* all outside points are color 0 */
(*plot)(col, row, color);
return color;
#undef CLOSE
#undef SQRT3
#undef A
#undef B1
#undef XMIDT
#undef M2
#undef B2
#undef M3
#undef B3
#undef X1MIN
#undef X1MAX
#undef X2MAX1
#undef XMIDR
#undef X3MIN1
#undef X2MIN2
#undef XMIDL
#undef X3MAX2
#undef FROTH_BITSHIFT
#undef D_TO_L
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -