📄 lorenz.c
字号:
if (++color >= colors) /* another color to switch to? */
color = 1; /* (don't use the background color) */
}
col = (multiply(cvt.a,x,bitshift) + multiply(cvt.b,y,bitshift) + cvt.e) >> bitshift;
row = (multiply(cvt.c,x,bitshift) + multiply(cvt.d,y,bitshift) + cvt.f) >> bitshift;
if(overflow)
{
overflow = 0;
return(ret);
}
if ( col >= 0 && col < xdots && row >= 0 && row < ydots )
{
if (soundflag > 0)
{
double yy;
yy = *soundvar;
yy = yy/fudge;
snd((int)(yy*100+basehertz));
}
if(oldcol != -1 && connect)
draw_line(col,row,oldcol,oldrow,color&(colors-1));
else if(!start)
(*plot)(col,row,color&(colors-1));
oldcol = col;
oldrow = row;
start = 0;
}
else if((long)abs(row) + (long)abs(col) > BAD_PIXEL) /* sanity check */
return(ret);
else
oldrow = oldcol = -1;
/* Calculate the next point */
if(curfractalspecific->orbitcalc(p0, p1, p2))
break;
if(fp)
fprintf(fp,orbitsave_format,(double)*p0/fudge,(double)*p1/fudge,0.0);
}
if(fp)
fclose(fp);
return(ret);
}
int orbit3dlongcalc()
{
FILE *fp;
unsigned count;
int oldcol,oldrow;
int oldcol1,oldrow1;
struct long3dvtinf inf;
unsigned long maxct;
int color;
int ret;
/* setup affine screen coord conversion */
l_setup_convert_to_screen(&inf.cvt);
oldcol1 = oldrow1 = oldcol = oldrow = -1;
color = 2;
if(color >= colors)
color = 1;
inf.orbit[0] = initorbitlong[0];
inf.orbit[1] = initorbitlong[1];
inf.orbit[2] = initorbitlong[2];
if(diskvideo) /* this would KILL a disk drive! */
notdiskmsg();
fp = open_orbitsave();
/* make maxct a function of screen size */
maxct = maxit*40L;
count = inf.ct = 0L;
ret = 0;
while(inf.ct++ < maxct) /* loop until keypress or maxit */
{
/* calc goes here */
if (++count > 1000)
{ /* time to switch colors? */
count = 0;
if (++color >= colors) /* another color to switch to? */
color = 1; /* (don't use the background color) */
}
if(check_key())
{
nosnd();
ret = -1;
break;
}
curfractalspecific->orbitcalc(&inf.orbit[0],&inf.orbit[1],&inf.orbit[2]);
if(fp)
fprintf(fp,orbitsave_format,(double)inf.orbit[0]/fudge,(double)inf.orbit[1]/fudge,(double)inf.orbit[2]/fudge);
if (long3dviewtransf(&inf))
{
/* plot if inside window */
if (inf.col >= 0)
{
if(realtime)
whichimage=1;
if (soundflag > 0)
{
double yy;
yy = inf.viewvect[soundflag-1];
yy = yy/fudge;
snd((int)(yy*100+basehertz));
}
if(oldcol != -1 && connect)
draw_line(inf.col,inf.row,oldcol,oldrow,color&(colors-1));
else
(*plot)(inf.col,inf.row,color&(colors-1));
}
else if (inf.col == -2)
return(ret);
oldcol = inf.col;
oldrow = inf.row;
if(realtime)
{
whichimage=2;
/* plot if inside window */
if (inf.col1 >= 0)
{
if(oldcol1 != -1 && connect)
draw_line(inf.col1,inf.row1,oldcol1,oldrow1,color&(colors-1));
else
(*plot)(inf.col1,inf.row1,color&(colors-1));
}
else if (inf.col1 == -2)
return(ret);
oldcol1 = inf.col1;
oldrow1 = inf.row1;
}
}
}
if(fp)
fclose(fp);
return(ret);
}
int orbit3dfloatcalc()
{
FILE *fp;
unsigned count;
int oldcol,oldrow;
int oldcol1,oldrow1;
extern int init3d[];
unsigned long maxct;
int color;
int ret;
struct float3dvtinf inf;
/* setup affine screen coord conversion */
setup_convert_to_screen(&inf.cvt);
oldcol = oldrow = -1;
oldcol1 = oldrow1 = -1;
color = 2;
if(color >= colors)
color = 1;
inf.orbit[0] = initorbit[0];
inf.orbit[1] = initorbit[1];
inf.orbit[2] = initorbit[2];
if(diskvideo) /* this would KILL a disk drive! */
notdiskmsg();
fp = open_orbitsave();
maxct = maxit*40L;
count = inf.ct = 0L;
ret = 0;
while(inf.ct++ < maxct) /* loop until keypress or maxit */
{
/* calc goes here */
if (++count > 1000)
{ /* time to switch colors? */
count = 0;
if (++color >= colors) /* another color to switch to? */
color = 1; /* (don't use the background color) */
}
if(check_key())
{
nosnd();
ret = -1;
break;
}
curfractalspecific->orbitcalc(&inf.orbit[0],&inf.orbit[1],&inf.orbit[2]);
if(fp)
fprintf(fp,orbitsave_format,inf.orbit[0],inf.orbit[1],inf.orbit[2]);
if (float3dviewtransf(&inf))
{
/* plot if inside window */
if (inf.col >= 0)
{
if(realtime)
whichimage=1;
if (soundflag > 0)
snd((int)(inf.viewvect[soundflag-1]*100+basehertz));
if(oldcol != -1 && connect)
draw_line(inf.col,inf.row,oldcol,oldrow,color&(colors-1));
else
(*plot)(inf.col,inf.row,color&(colors-1));
}
else if (inf.col == -2)
return(ret);
oldcol = inf.col;
oldrow = inf.row;
if(realtime)
{
whichimage=2;
/* plot if inside window */
if (inf.col1 >= 0)
{
if(oldcol1 != -1 && connect)
draw_line(inf.col1,inf.row1,oldcol1,oldrow1,color&(colors-1));
else
(*plot)(inf.col1,inf.row1,color&(colors-1));
}
else if (inf.col1 == -2)
return(ret);
oldcol1 = inf.col1;
oldrow1 = inf.row1;
}
}
}
if(fp)
fclose(fp);
return(ret);
}
int dynam2dfloatsetup()
{
connect = 0;
euler = 0;
d = param[0]; /* number of intervals */
if (d<0) {
d = -d;
connect = 1;
}
else if (d==0) {
d = 1;
}
if (fractype==DYNAMICFP) {
a = param[2]; /* parameter */
b = param[3]; /* parameter */
dt = param[1]; /* step size */
if (dt<0) {
dt = -dt;
euler = 1;
}
if (dt==0) dt = 0.01;
}
if (outside == -5) {
plot = plothist;
}
return(1);
}
/*
* This is the routine called to perform a time-discrete dynamical
* system image.
* The starting positions are taken by stepping across the image in steps
* of parameter1 pixels. maxit differential equation steps are taken, with
* a step size of parameter2.
*/
int dynam2dfloat()
{
FILE *fp;
double *soundvar;
double x,y,z;
int color,col,row;
int count;
int oldrow, oldcol;
double *p0,*p1;
struct affine cvt;
int ret;
int xstep, ystep; /* The starting position step number */
double xpixel, ypixel; /* Our pixel position on the screen */
fp = open_orbitsave();
/* setup affine screen coord conversion */
setup_convert_to_screen(&cvt);
p0 = &x;
p1 = &y;
if(soundflag==1)
soundvar = &x;
else if(soundflag==2)
soundvar = &y;
else if(soundflag==3)
soundvar = &z;
count = 0;
if(inside > 0)
color = inside;
if(color >= colors)
color = 1;
oldcol = oldrow = -1;
xstep = -1;
ystep = 0;
if (resuming) {
start_resume();
get_resume(sizeof(count),&count, sizeof(color),&color,
sizeof(oldrow),&oldrow, sizeof(oldcol),&oldcol,
sizeof(x),&x, sizeof(y), &y, sizeof(xstep), &xstep,
sizeof(ystep), &ystep, 0);
end_resume();
}
ret = 0;
while(1)
{
if(check_key())
{
nosnd();
alloc_resume(100,1);
put_resume(sizeof(count),&count, sizeof(color),&color,
sizeof(oldrow),&oldrow, sizeof(oldcol),&oldcol,
sizeof(x),&x, sizeof(y), &y, sizeof(xstep), &xstep,
sizeof(ystep), &ystep, 0);
ret = -1;
break;
}
xstep ++;
if (xstep>=d) {
xstep = 0;
ystep ++;
if (ystep>d) {
nosnd();
ret = -1;
break;
}
}
xpixel = dxsize*(xstep+.5)/d;
ypixel = dysize*(ystep+.5)/d;
x = (xxmin+delxx*xpixel) + (delxx2*ypixel);
y = (yymax-delyy*ypixel) + (-delyy2*xpixel);
if (fractype==MANDELCLOUD) {
a = x;
b = y;
}
oldcol = -1;
if (++color >= colors) /* another color to switch to? */
color = 1; /* (don't use the background color) */
for (count=0;count<maxit;count++) {
col = cvt.a*x + cvt.b*y + cvt.e;
row = cvt.c*x + cvt.d*y + cvt.f;
if ( col >= 0 && col < xdots && row >= 0 && row < ydots )
{
if (soundflag > 0)
snd((int)(*soundvar*100+basehertz));
if (count>=orbit_delay) {
if(oldcol != -1 && connect)
draw_line(col,row,oldcol,oldrow,color&(colors-1));
else if(count > 0 || fractype != MANDELCLOUD)
(*plot)(col,row,color&(colors-1));
}
oldcol = col;
oldrow = row;
}
else if((long)abs(row) + (long)abs(col) > BAD_PIXEL) /* sanity check */
return(ret);
else
oldrow = oldcol = -1;
if(curfractalspecific->orbitcalc(p0, p1, NULL))
break;
if(fp)
fprintf(fp,orbitsave_format,*p0,*p1,0.0);
}
}
if(fp)
fclose(fp);
return(ret);
}
/* this function's only purpose is to manage funnyglasses related */
/* stuff so the code is not duplicated for ifs3d() and lorenz3d() */
int funny_glasses_call(int (*calc)())
{
int status;
status = 0;
if(glassestype)
whichimage = 1;
else
whichimage = 0;
plot_setup();
plot = standardplot;
status = calc();
if(realtime && glassestype != 3)
{
realtime = 0;
return(status);
}
if(glassestype && status == 0 && display3d)
{
if(glassestype==3) /* photographer's mode */
if(active_system == 0) { /* dos version */
int i;
static char far firstready[]={"\
First image (left eye) is ready. Hit any key to see it,\n\
then hit <s> to save, hit any other key to create second image."};
stopmsg(16,firstready);
while ((i = getakey()) == 's' || i == 'S') {
diskisactive = 1;
savetodisk(savename);
diskisactive = 0;
}
/* is there a better way to clear the screen in graphics mode? */
setvideomode(videoentry.videomodeax,
videoentry.videomodebx,
videoentry.videomodecx,
videoentry.videomodedx);
}
else { /* Windows version */
static char far firstready2[]={"First (Left Eye) image is complete"};
stopmsg(0,firstready2);
clear_screen();
}
whichimage = 2;
plot_setup();
plot = standardplot;
/* is there a better way to clear the graphics screen ? */
if(status = calc())
return(status);
if(glassestype==3) /* photographer's mode */
if(active_system == 0) { /* dos version */
static char far secondready[]={"Second image (right eye) is ready"};
stopmsg(16,secondready);
}
}
return(status);
}
/* double version - mainly for testing */
static int ifs3dfloat()
{
int color_method;
FILE *fp;
unsigned long maxct;
int color;
double newx,newy,newz,r,sum;
int k;
int ret;
struct float3dvtinf inf;
float far *ffptr;
/* setup affine screen coord conversion */
setup_convert_to_screen(&inf.cvt);
srand(1);
color_method = param[0];
if(diskvideo) /* this would KILL a disk drive! */
notdiskmsg();
inf.orbit[0] = 0;
inf.orbit[1] = 0;
inf.orbit[2] = 0;
fp = open_orbitsave();
maxct = maxit*40L;
inf.ct = 0L;
ret = 0;
while(inf.ct++ < maxct) /* loop until keypress or maxit */
{
if( check_key() ) /* keypress bails out */
{
ret = -1;
break;
}
r = rand15(); /* generate fudged random number between 0 and 1 */
r /= 32767;
/* pick which iterated function to execute, weighted by probability */
sum = ifs_defn[12]; /* [0][12] */
k = 0;
while ( sum < r)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -