home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_10 / 8n10109a < prev    next >
Text File  |  1990-07-03  |  2KB  |  52 lines

  1. // mandel.c - Zortech C++ program to draw Mandelbrot set.
  2. #include <conio.h>
  3. #include "fg.h"
  4. #include "dcomplex.h"
  5.  
  6. inline float scale(int point, int maxpoint)
  7.     {
  8.     maxpoint    /= 2;
  9.     return 2 * (point - maxpoint)/float(maxpoint);
  10.     }
  11. int     resolution    = 50;
  12. int     maxrow;
  13. int     maxcol;
  14.  
  15. int     mandel(float row, float col)
  16.     {
  17.     DComplex    Z(0,0);
  18.     DComplex    C(col, row);
  19.     int color       = 0;
  20.     for(int iter = 0; iter < resolution && abs(Z) < 2.0; ++iter, ++color)
  21.         Z   = Z * Z + C;
  22.     return iter < resolution ? color : 0;
  23.     }
  24.  
  25. int     main(int argc, char **argv)
  26.     {
  27.     int     status  = fg_init();        // initialize graphics package
  28.     maxrow  = fg.displaybox[FG_Y2];
  29.     maxcol  = fg.displaybox[FG_X2];
  30.     int     maxcolor    = fg.nsimulcolor;
  31.     if(status != 0)
  32.         {
  33.         int     step    = 20;
  34.         for(resolution = 1; !kbhit(); ++resolution)
  35.             {
  36.             for(int col=maxcol; col >= 0 && !kbhit(); col -= step)
  37.                 for(int row = 0; row <= maxrow/2; row += step)
  38.                     {
  39.                     int color   = mandel(scale(row,maxrow),
  40.                                          scale(col,maxcol))
  41.                                 % maxcolor;
  42.                     fg_drawdot(color, FG_MODE_SET, ~0, col, row);
  43.                     fg_drawdot(color, FG_MODE_SET, ~0, col, maxrow-row);
  44.                     }
  45.             if(step > 1) --step;
  46.             }
  47.         while(!kbhit())     // hit key to terminate program
  48.             ;
  49.         fg_term();          // return to text mode
  50.         }
  51.     }
  52.