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

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