home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / ZCOMPLEX.ZIP / MUTANT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-18  |  3.2 KB  |  113 lines

  1.  
  2. //    MUTANT.CPP - a slightly modified version of biomorph
  3.  
  4. //    Program:    Biomorph   (generate non-standard fractals)
  5. //    Version:        1.02   17-Mar-1990 mods by Ashley Roeckelein
  6. //            1.01   31-Oct-1989
  7. //    Language:    C++ 2.0;  Environ: Any;  Compilers: Zortech C++ 2.01
  8. //    Purpose:    Generates fractals based on complex number formula
  9. //            iterations.
  10. //    Written by:    Scott Robert Ladd, 705 West Virginia, Gunnison CO 81230
  11. //            BBS (303)641-6438; FidoNet 1:104/708
  12.  
  13. //    ***** Modified to work with Zortech's Flash Graphics Library *****
  14.  
  15. #include <conio.h>
  16. #include <fg.h>
  17. #include "complex.hpp"
  18.  
  19. Complex        c, z, power;
  20. double        range, xInc, yInc, xMax, yMax, xOrig, yOrig;
  21. int        x, y, i, iter, species;
  22.  
  23. void        getParms ();
  24. int        main ();
  25.  
  26. void
  27. getParms (
  28.     void
  29. ) {
  30.     cout << "Biomorph 1.02 - complex-plane fractal generator\n\n";
  31.     cout << "This program generates these species of biomorphs...\n";
  32.     cout << "  Species 0: z^x + c          Species 1: sin(z) + exp(z) + c\n";
  33.     cout << "  Species 2: z^x + z^x + c   Species 3: sin(z) + z^x + c\n";
  34.     do {
  35.         cout << "What species do you want (0..3)? ";
  36.         cin >> species;
  37.     } while ( ( species < 0) || ( species > 3));
  38.     cout << "\nWe need one or two complex numbers.  These can be entered\n";
  39.     cout << "in the following formats (where 'f' indicates a floating-point\n";
  40.     cout << "value:\n";
  41.     cout << "    f -or- (f)  (just a real number)\n";
  42.     cout << "    (f,f)     (entering both the real and imaginary parts)\n";
  43.     if ( species != 1) {
  44.         cout << "Enter the complex power applied to z: ";
  45.         cin >> power;
  46.     }
  47.     cout << "Enter the complex constant c: ";
  48.     cin >> c;
  49.     cout << "The next two numbers are floating point values representing the\n";
  50.     cout << "origin point on the complex plane of the area being viewed.\n\n";
  51.     cout << "Enter the X location of the center of the picture: ";
  52.     cin >> xOrig;
  53.     cout << "Enter the Y location of the center of the picture: ";
  54.     cin >> yOrig;
  55.     cout << "\nThe next number represents the distance the graph extends away\n";
  56.     cout << "from the above origin.\n\n";
  57.     cout << "Enter the range of the graph: ";
  58.     cin >> range;
  59.     cout << "\nFinally, how many iterations should the program perform?";
  60.     cin >> iter;
  61. }
  62.  
  63. int
  64. main (
  65. ) {
  66.     getParms ();
  67.     fg_init_all ();
  68.     if ( fg_display == FG_CGAHIRES) {
  69.         fg_term ();
  70.         fg_init_cgamedres ();
  71.     }
  72.     yMax = fg_displaybox [ FG_Y2] + 1;
  73.     xMax = fg_displaybox [ FG_X2] + 1;
  74.     yInc = 2.0 * range / yMax;
  75.     xInc = 2.0 * range / xMax;
  76.     range = -range;
  77.     for ( x = 0; x < xMax; x++) {
  78.         for ( y = 0; y < yMax; y++) {
  79.             z = Complex ( range + xInc * x + xOrig,
  80.                 range + yInc * y + yOrig);
  81.             for ( i = 0; i < iter; i++) {
  82.                 switch ( species) {
  83.                     case 0:    z = pow ( z, power) + c;
  84.                         break;
  85.                     case 1: z = sin ( z) + exp ( z) + c;
  86.                         break;
  87.                     case 2:    z = pow ( z, z) +
  88.                             pow ( z, power) + c;
  89.                         break;
  90.                     case 3:    z = sin ( z) +
  91.                             pow ( z, power) + c;
  92.                         break;
  93.                 }
  94.                 if ( abs ( real ( z)) > 10.0 ||
  95.                     abs ( imag ( z)) > 10.0 ||
  96.                     norm ( z) >= 100.0)
  97.                     break;
  98.             }
  99.             fg_drawdot ( ( fg_color_t) ( ( int) abs ( z)) %
  100.                 fg_ncolormap, FG_MODE_SET, ~0, x, y);
  101.         }
  102.         if ( kbhit ())
  103.             break;
  104.     } while ( !kbhit ());
  105.     if ( !getch ())
  106.         getch ();
  107.     fg_term ();
  108.     return 0;
  109. }
  110.  
  111.  
  112.  
  113.