home *** CD-ROM | disk | FTP | other *** search
/ MS DOS Archives 1 / MS-DOS_Archives_Volume_One_Walnut_Creek.iso / msdos / graphics / hgrph101.arc / MANDEL.C < prev    next >
C/C++ Source or Header  |  1989-02-25  |  1KB  |  39 lines

  1. #include "hgraph.h"
  2.  
  3. /*  Subroutine MANDEL()   */
  4.  
  5.  
  6. #define sqr(x) (x*x)
  7. #define MAX_ITERATIONS 100
  8. #define MAX_SIZE       4
  9. #define MAX_ROW        347
  10. #define MAX_COL        719
  11.  
  12. #define MAX_COLORS 2
  13.  
  14. void mandel (pmax, pmin, qmax, qmin)
  15. double pmax, pmin, qmax,  qmin;
  16. {
  17.   int color, row, col;
  18.   double p, q, modulus, deltap, deltaq, Xcur, Xlast, Ycur, Ylast;
  19.  
  20.   deltap = (pmax - pmin) / (MAX_COL - 1);
  21.   deltaq = (qmax - qmin) / (MAX_ROW - 1);
  22.   for (col = 0; col <= MAX_COL; col++)
  23.      for (row = 0; row <= MAX_ROW; row++) {
  24.         p = pmin + col * deltap;
  25.         q = qmin + row * deltaq;
  26.         Xlast = Ylast = modulus = 0.0;
  27.         color = 0;
  28.         while ( (modulus < MAX_SIZE) && (color < MAX_ITERATIONS) ) {
  29.            Xcur = sqr (Xlast) - sqr (Ylast) + p;
  30.            Ycur = 2 * Xlast * Ylast + q;
  31.            color++;
  32.            Xlast = Xcur;
  33.            Ylast = Ycur;
  34.            modulus = sqr (Xcur) + sqr (Ycur);
  35.         }  /* while */
  36.         hpixel((color % MAX_COLORS),col,row);
  37.      }  /* for */
  38. }  /* mandel */
  39.