⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lorenz.c

📁 frasr200的win 版本源码(18.21),使用make文件,使用的vc版本较低,在我的环境下编译有问题! 很不错的分形程序代码!
💻 C
📖 第 1 页 / 共 5 页
字号:
      {
	 k++;
	 sum += ifs_defn[k*IFS3DPARM+12];
	 if (ifs_defn[(k+1)*IFS3DPARM+12] == 0) break; /* for safety */
      }

      /* calculate image of last point under selected iterated function */
      ffptr = ifs_defn + k*IFS3DPARM; /* point to first parm in row */
      newx = *ffptr * inf.orbit[0] +
	     *(ffptr+1) * inf.orbit[1] +
	     *(ffptr+2) * inf.orbit[2] + *(ffptr+9);
      newy = *(ffptr+3) * inf.orbit[0] +
	     *(ffptr+4) * inf.orbit[1] +
	     *(ffptr+5) * inf.orbit[2] + *(ffptr+10);
      newz = *(ffptr+6) * inf.orbit[0] +
	     *(ffptr+7) * inf.orbit[1] +
	     *(ffptr+8) * inf.orbit[2] + *(ffptr+11);

      inf.orbit[0] = newx;
      inf.orbit[1] = newy;
      inf.orbit[2] = newz;
      if(fp)
	  fprintf(fp,orbitsave_format,newx,newy,newz);
      if (float3dviewtransf(&inf))
      {
	 /* plot if inside window */
	 if (inf.col >= 0)
	 {
	    if(realtime)
	       whichimage=1;
            if(color_method)
               color = (k&(colors-1))+1;
            else
	    color = getcolor(inf.col,inf.row)+1;
	    if( color < colors ) /* color sticks on last value */
	       (*plot)(inf.col,inf.row,color);
	 }
         else if (inf.col == -2)
            return(ret);
	 if(realtime)
	 {
	    whichimage=2;
	    /* plot if inside window */
	    if (inf.col1 >= 0)
	    {
              if(color_method)
                 color = (k&(colors-1))+1;
              else
	        color = getcolor(inf.col1,inf.row1)+1;
	        if( color < colors ) /* color sticks on last value */
		  (*plot)(inf.col1,inf.row1,color);
	    }
	    else if (inf.col1 == -2)
               return(ret);
	 }
      }
   } /* end while */
   if(fp)
      fclose(fp);
   return(ret);
}

int ifs()			/* front-end for ifs2d and ifs3d */
{
   if (ifs_defn == NULL && ifsload() < 0)
      return(-1);
   if(diskvideo)                /* this would KILL a disk drive! */
      notdiskmsg();
   return((ifs_type == 0) ? ifs2d() : ifs3d());
}


/* IFS logic shamelessly converted to integer math */
int ifs2d()
{
   int color_method;
   FILE *fp;
   unsigned long maxct,ct;
   int col;
   int row;
   int color;
   int ret;
   long far *localifs;
   long far *lfptr;
   long x,y,newx,newy,r,sum, tempr;

   int i,j,k;
   struct l_affine cvt;
   /* setup affine screen coord conversion */
   l_setup_convert_to_screen(&cvt);

   srand(1);
   color_method = param[0];
   if((localifs=(long far *)farmemalloc((long)numaffine*IFSPARM*sizeof(long)))==NULL)
   {
      stopmsg(0,insufficient_ifs_mem);
      return(-1);
   }

   for (i = 0; i < numaffine; i++)    /* fill in the local IFS array */
      for (j = 0; j < IFSPARM; j++)
	 localifs[i*IFSPARM+j] = ifs_defn[i*IFSPARM+j] * fudge;

   tempr = fudge / 32767;	 /* find the proper rand() fudge */

   fp = open_orbitsave();

   /* make maxct a function of screen size		 */
   /* 1k times maxit at EGA resolution seems about right */
   maxct = (float)maxit*(1024.0*xdots*ydots)/(640.0*350.0);
   ct = 0L;
   x = y = 0;
   ret = 0;
   while(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 *= tempr;

      /* pick which iterated function to execute, weighted by probability */
      sum = localifs[6];  /* [0][6] */
      k = 0;
      while ( sum < r && k < numaffine-1) /* fixed bug of error if sum < 1 */
	 sum += localifs[++k*IFSPARM+6];
      /* calculate image of last point under selected iterated function */
      lfptr = localifs + k*IFSPARM; /* point to first parm in row */
      newx = multiply(lfptr[0],x,bitshift) + 
             multiply(lfptr[1],y,bitshift) + lfptr[4];
      newy = multiply(lfptr[2],x,bitshift) + 
             multiply(lfptr[3],y,bitshift) + lfptr[5];
      x = newx;
      y = newy;
      if(fp)
	 fprintf(fp,orbitsave_format,(double)newx/fudge,(double)newy/fudge,0.0);

      /* plot if inside window */
      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 ( col >= 0 && col < xdots && row >= 0 && row < ydots )
      {
	 /* color is count of hits on this pixel */
         if(color_method)
            color = (k&(colors-1))+1;
         else
	 color = getcolor(col,row)+1;
	 if( color < colors ) /* color sticks on last value */
	    (*plot)(col,row,color);
      }
      else if((long)abs(row) + (long)abs(col) > BAD_PIXEL) /* sanity check */
            return(ret);
   }
   if(fp)
      fclose(fp);
   farmemfree(localifs);
   return(ret);
}

static int ifs3dlong()
{
   int color_method;   
   FILE *fp;
   extern int init3d[];
   unsigned long maxct;
   int color;
   int ret;

   long far *localifs;
   long far *lfptr;
   long newx,newy,newz,r,sum, tempr;

   int i,j,k;

   struct long3dvtinf inf;
   srand(1);
   color_method = param[0];
   if((localifs=(long far *)farmemalloc((long)numaffine*IFS3DPARM*sizeof(long)))==NULL)
   {
      stopmsg(0,insufficient_ifs_mem);
      return(-1);
   }

   /* setup affine screen coord conversion */
   l_setup_convert_to_screen(&inf.cvt);

   for (i = 0; i < numaffine; i++)    /* fill in the local IFS array */
      for (j = 0; j < IFS3DPARM; j++)
	 localifs[i*IFS3DPARM+j] = ifs_defn[i*IFS3DPARM+j] * fudge;

   tempr = fudge / 32767;	 /* find the proper rand() fudge */

   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 *= tempr;

      /* pick which iterated function to execute, weighted by probability */
      sum = localifs[12];  /* [0][12] */
      k = 0;
      while ( sum < r && ++k < numaffine*IFS3DPARM)
	 sum += localifs[k*IFS3DPARM+12];

      /* calculate image of last point under selected iterated function */
      lfptr = localifs + k*IFS3DPARM; /* point to first parm in row */

      /* calculate image of last point under selected iterated function */
      newx = multiply(lfptr[0], inf.orbit[0], bitshift) +
             multiply(lfptr[1], inf.orbit[1], bitshift) +
	     multiply(lfptr[2], inf.orbit[2], bitshift) + lfptr[9];
      newy = multiply(lfptr[3], inf.orbit[0], bitshift) +
	     multiply(lfptr[4], inf.orbit[1], bitshift) +
	     multiply(lfptr[5], inf.orbit[2], bitshift) + lfptr[10];
      newz = multiply(lfptr[6], inf.orbit[0], bitshift) +
	     multiply(lfptr[7], inf.orbit[1], bitshift) +
	     multiply(lfptr[8], inf.orbit[2], bitshift) + lfptr[11];

      inf.orbit[0] = newx;
      inf.orbit[1] = newy;
      inf.orbit[2] = newz;
      if(fp)
	 fprintf(fp,orbitsave_format,(double)newx/fudge,(double)newy/fudge,(double)newz/fudge);

      if (long3dviewtransf(&inf))
      {
	 if((long)abs(inf.row) + (long)abs(inf.col) > BAD_PIXEL) /* sanity check */
            return(ret);
	 /* plot if inside window */
	 if (inf.col >= 0)
	 {
	    if(realtime)
	       whichimage=1;
            if(color_method)
               color = (k&(colors-1))+1;
            else
	    color = getcolor(inf.col,inf.row)+1;
	    if( color < colors ) /* color sticks on last value */
	       (*plot)(inf.col,inf.row,color);
	 }
	 if(realtime)
	 {
	    whichimage=2;
	    /* plot if inside window */
	    if (inf.col1 >= 0)
	    {
               if(color_method)
                  color = (k&(colors-1))+1;
               else
	       color = getcolor(inf.col1,inf.row1)+1;
	       if( color < colors ) /* color sticks on last value */
		  (*plot)(inf.col1,inf.row1,color);
	    }
	 }
      }
   }
   if(fp)
      fclose(fp);
   farmemfree(localifs);
   return(ret);
}

static void setupmatrix(MATRIX doublemat)
{
   /* build transformation matrix */
   identity (doublemat);

   /* apply rotations - uses the same rotation variables as line3d.c */
   xrot ((double)XROT / 57.29577,doublemat);
   yrot ((double)YROT / 57.29577,doublemat);
   zrot ((double)ZROT / 57.29577,doublemat);

   /* apply scale */
/*   scale((double)XSCALE/100.0,(double)YSCALE/100.0,(double)ROUGH/100.0,doublemat);*/

}

int orbit3dfloat()
{
   display3d = -1;
   if(0 < glassestype && glassestype < 3)
      realtime = 1;
   else
      realtime = 0;
   return(funny_glasses_call(orbit3dfloatcalc));
}

int orbit3dlong()
{
   display3d = -1;
   if(0 < glassestype && glassestype < 3)
      realtime = 1;
   else
      realtime = 0;
   return(funny_glasses_call(orbit3dlongcalc));
}

int ifs3d()
{
   display3d = -1;

   if(0 < glassestype && glassestype < 3)
      realtime = 1;
   else
      realtime = 0;
   if(floatflag)
      return(funny_glasses_call(ifs3dfloat)); /* double version of ifs3d */
   else
      return(funny_glasses_call(ifs3dlong));  /* long version of ifs3d	 */
}



static int long3dviewtransf(struct long3dvtinf *inf)
{
   int i,j;
   double tmpx, tmpy, tmpz;
   long tmp;

   if (inf->ct == 1)	/* initialize on first call */
   {
      for(i=0;i<3;i++)
      {
	 inf->minvals[i] =  1L << 30;
	 inf->maxvals[i] = -inf->minvals[i];
      }
      setupmatrix(inf->doublemat);
      if(realtime)
	 setupmatrix(inf->doublemat1);
      /* copy xform matrix to long for for fixed point math */
      for (i = 0; i < 4; i++)
	 for (j = 0; j < 4; j++)
	 {
	    inf->longmat[i][j] = inf->doublemat[i][j] * fudge;
	    if(realtime)
	       inf->longmat1[i][j] = inf->doublemat1[i][j] * fudge;
	 }
   }

   /* 3D VIEWING TRANSFORM */
   longvmult(inf->orbit,inf->longmat,inf->viewvect,bitshift);
   if(realtime)
      longvmult(inf->orbit,inf->longmat1,inf->viewvect1,bitshift);

   if(inf->ct <= waste) /* waste this many points to find minz and maxz */
   {
      /* find minz and maxz */
      for(i=0;i<3;i++)
	 if ((tmp = inf->viewvect[i]) < inf->minvals[i])
	    inf->minvals[i] = tmp;
	 else if (tmp > inf->maxvals[i])
	    inf->maxvals[i] = tmp;

      if(inf->ct == waste) /* time to work it out */
      {
	 inf->iview[0] = inf->iview[1] = 0L; /* center viewer on origin */

	 /* z value of user's eye - should be more negative than extreme
			negative part of image */
	 inf->iview[2] = (long)((inf->minvals[2]-inf->maxvals[2])*(double)ZVIEWER/100.0);

	 /* center image on origin */
	 tmpx = (-inf->minvals[0]-inf->maxvals[0])/(2.0*fudge); /* center x */
	 tmpy = (-inf->minvals[1]-inf->maxvals[1])/(2.0*fudge); /* center y */

	 /* apply perspective shift */
	 tmpx += ((double)xshift*(xxmax-xxmin))/(xdots);
	 tmpy += ((double)yshift*(yymax-yymin))/(ydots);
	 tmpz = -((double)inf->maxvals[2]) / fudge;
	 trans(tmpx,tmpy,tmpz,inf->doublemat);

	 if(realtime)
	 {
	    /* center image on origin */
	    tmpx = (-inf->minvals[0]-inf->maxvals[0])/(2.0*fudge); /* center x */
	    tmpy = (-inf->minvals[1]-inf->maxvals[1])/(2.0*fudge); /* center y */

	    tmpx += ((double)xshift1*(xxmax-xxmin))/(xdots);
	    tmpy += ((double)yshift1*(yymax-yymin))/(ydots);
	    tmpz = -((double)inf->maxvals[2]) / fudge;
	    trans(tmpx,tmpy,tmpz,inf->doublemat1);
	 }
	 for(i=0;i<3;i++)
	    view[i] = (double)inf->iview[i] / fudge;

	 /* copy xform matrix to long for for fixed point math */
	 for (i = 0; i < 4; i++)
	    for (j = 0; j < 4; j++)
	    {
	       inf->longmat[i][j] = inf->doublemat[i][j] * fudge;
	       if(realtime)
		  inf->longmat1[i][j] = inf->doublemat1[i][j] * fudge;
	    }
      }
      return(0);
   }

   /* inf->ct > waste */
   /* apply perspective if requested */
   if(ZVIEWER)
   {
      if(debugflag==22 || ZVIEWER < 100) /* use float for small persp */
      {
	 /* use float perspective calc */
	 VECTOR tmpv;
	 for(i=0;i<3;i++)
	    tmpv[i] = (double)inf->viewvect[i] / fudge;
	 perspective(tmpv);
	 for(i=0;i<3;i++)
	    inf->viewvect[i] = tmpv[i]*fudge;
	 if(realtime)
	 {
	    for(i=0;i<3;i++)
	       tmpv[i] = (double)inf->viewvect1[i] / fudge;
	    perspective(tmpv);
	    for(i=0;i<3;i++)
	       inf->viewvect1[i] = tmpv[i]*fudge;
	 }
      }
      else
      {
	 longpersp(inf->viewvect,inf->iview,bitshift);
	 if(realtime)
	    longpersp(inf->viewvect1,inf->iview,bitshift);
      }
   }

   /* work out the screen positions */
   inf->row = ((multiply(inf->cvt.c,inf->viewvect[0],bitshift) +
		multiply(inf->cvt.d,inf->viewvect[1],bitshift) + inf->cvt.f)
		>> bitshift)
	      + yyadjust;
   inf->col = ((multiply(inf->cvt.a,inf->viewvect[0],bitshift) +
		multiply(inf->cvt.b,inf->viewvect[1],bitshift) + inf->cvt.e)
		>> bitshift)
	      + xxadjust;
   if (inf->col < 0 || inf->col >= xdots || inf->row < 0 || inf->row >= ydots)
   {
      if((long)abs(inf->col)+(long)abs(inf->row) > BAD_PIXEL)
        inf->col= inf->row = -2;
      else
        inf->col= inf->row = -1;
   }    
   if(realtime)
   {
      inf->row1 = ((multiply(inf->cvt.c,inf->viewvect1[0],bitshift) +
		    multiply(inf->cvt.d,inf->viewvect1[1],bitshift) +
		    inf->cvt.f) >> bitshift)
		  + yyadjust1;
      inf->col1 = ((multiply(inf->cvt.a,inf->viewvect1[0],bitshift) +
		    multiply(inf->cvt.b,inf->viewvect1[1],bitshift) +
		    inf->cvt.e) >> bitshift)
		  + xxadjust1;
      if (inf->col1 < 0 || inf->col1 >= xdots || inf->row1 < 0 || inf->row1 >= ydots)
      {
         if((long)abs(inf->col1)+(long)abs(inf->row1) > BAD_PIXEL)
           inf->col1= inf->row1 = -2;
         else
           inf->col1= inf->row1 = -1;
      }    
   }
   return(1);
}

static int float3dviewtransf(struct float3dvtinf *inf)
{
   int i;
   double tmpx, tmpy, tmpz;
   double tmp;

   if (inf->ct == 1)	/* initialize on first call */
   {
      for(i=0;i<3;i++)
      {
	 inf->minvals[i] =  100000.0; /* impossible value */
	 inf->maxvals[i] = -100000.0;
      }
      set

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -