home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / cebit_91 / biomorph / biomorph.c next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  6.3 KB  |  190 lines

  1. /**********************************************************/
  2. /*                                                        */
  3. /*                         BIOMORPH                       */
  4. /* Ein Programm zur Erzeugung von sog. 'Biomorphen' nach  */
  5. /*   C. A. Pickover, beschrieben von A. K. Dewdney in     */
  6. /* 'Spektrum der Wissenschaft', Sonderheft 10, S. 60 ff.  */
  7. /*                                                        */
  8. /* Dient zur Demonstration der INCLUDE-Datei 'complex.c'  */
  9. /*                                                        */
  10. /*                 Sprache: Turbo C 2.0                   */
  11. /*        (C) 1991 Ralf Baethke-Franke & toolbox          */
  12. /*                                                        */
  13. /**********************************************************/
  14.  
  15. #include <graphics.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <math.h>
  19. #include <dos.h>
  20. #include "complex.c"
  21.  
  22. /* Globale Variable */
  23.  
  24. compl z,z0,c;
  25. int j,k,n,iter,farben;
  26. float rmin,rmax,imin,imax;
  27. int funktion;
  28. int xasp,yasp,x,y;
  29.  
  30. /* Funktionsprototypen */
  31.  
  32. void Rechnen     ( void );
  33. void main        ( void );
  34. void Eingabe     ( void );
  35. void Grafik      ( void );
  36. int  round       ( double v );
  37. void Einheiten   ( int g, double b, double c, int x1,
  38.                                                                                                         int y1, char achse );
  39. void Koordinaten ( void );
  40.  
  41. /* Funktionen */
  42.  
  43. void Rechnen ( void )
  44. {
  45.         z = sqr_c(z);
  46. }
  47.  
  48. void main ( void )
  49. {
  50.         double a,b;
  51.  
  52.         Eingabe ();
  53.         sound ( 1000 ); delay ( 10 ); nosound ();
  54.         Grafik ();
  55.         Koordinaten ();
  56.         a = ( rmax - rmin ) / x;
  57.         b = ( imax - imin ) / y;
  58.         for ( j = 0; j < x; j++ )
  59.         {
  60.                 for ( k = 0; k < y; k++ )
  61.                 {
  62.                         z0.re = rmin + a * j;
  63.                         z0.im = imin + b * k;
  64.                         z = z0;
  65.                         for ( n = 1; n < iter + 1; n++)
  66.                         {
  67.  
  68.                                 if ( kbhit () != 0 )
  69.                                 {
  70.                                         if ( getch () == 27 )
  71.                                         {
  72.                                                 restorecrtmode ();
  73.                                                 exit ( 0 );
  74.                                         }
  75.                                 }
  76.                                 Rechnen ();
  77.                                 z = add_c ( z, c );
  78.  
  79.                                 if ( abs ( z.re ) > 10 || abs ( z.im ) > 10 )
  80.                                         break;
  81.                         }
  82.                         if ( abs ( z.re ) < 10 || abs ( z.im ) < 10 )
  83.                         {
  84.                                 while ( n > farben ) n -= farben;
  85.                                 if ( n == farben ) n -= 1;
  86.                                 if ( getpixel ( j + 50, y + 25 - k ) != WHITE )
  87.                                         putpixel ( j + 50, y + 25 - k, n );
  88.                         }
  89.                 }
  90.         }
  91.         sound ( 2000 ); delay ( 500 ); nosound ();
  92.         getch ();
  93. }
  94.  
  95. void Eingabe ( void )
  96. {
  97.         float c1;
  98.  
  99.         clrscr ();
  100.         gotoxy ( 32, 1 );
  101.         highvideo ();
  102.         cprintf ( "B I O M O R P H" );
  103.         gotoxy ( 32, 2 );
  104.         cprintf ( "===============" );
  105.         lowvideo ();
  106.         printf ( "\n\nUntere Grenze für die reelle Achse   : " );
  107.         scanf ( "%f", &rmin );
  108.         printf ( "Obere Grenze für die reelle Achse    : " );
  109.         scanf ( "%f", &rmax );
  110.         printf ( "Untere Grenze für die imaginäre Achse: " );
  111.         scanf ( "%f", &imin );
  112.         imax = imin + ( rmax - rmin );
  113.         printf ( "Obere Grenze für die imaginäre Achse : %.2f\n",
  114.                                                                                                                                           imax );
  115.         printf ( "\nRealteil der Konstante   : " );
  116.         scanf ( "%f", &c1 );
  117.         c.re = c1;
  118.         printf ( "Imaginärteil der Konstante: " );
  119.         scanf ( "%f", &c1 );
  120.         c.im = c1;
  121.         printf ( "\nAnzahl Iterationen: " );
  122.         scanf ( "%d", &iter );
  123. }
  124.  
  125. void Grafik ( void )
  126. {
  127.         int gd, gm;
  128.  
  129.         detectgraph ( &gd, &gm );
  130.         initgraph ( &gd, &gm, "" );
  131.         getaspectratio ( &xasp, &yasp );
  132.         y = getmaxy () - 50;
  133.         x = (int) ( ( long ) y * ( long ) yasp / ( long ) xasp );
  134.         farben = getmaxcolor () + 1;
  135. }
  136.  
  137. int round ( double v )
  138. {
  139.         return ( floor ( v + 0.5 ) );
  140. }
  141.  
  142. void Einheiten ( int g, double b, double c, int x1, int y1,
  143.                                                                                                                                  char achse)
  144. {
  145.         int a, e;
  146.  
  147.         if (achse == 'x')
  148.         {
  149.                 for ( a = 0; a <= g; a++)
  150.                 {
  151.                         e = x1 + round ( ( a * b ) / ( 10 * c ) );
  152.                         line ( e, y1 - 3, e, y1 + 3 );
  153.                         if ( !(a % 5) )  line ( e, y1 - 4, e, y1 + 4 );
  154.                         if ( !(a % 10) ) line ( e, y1 - 5, e, y1 + 5 );
  155.                 }
  156.         }
  157.  
  158.         if ( achse == 'y' )
  159.         {
  160.                 for ( a = 0; a <= g; a++)
  161.                 {
  162.                         e = y1 - round ( ( a * b ) / ( 10 * c ) );
  163.                         line ( x1 - 3, e, x1 + 3, e );
  164.                         if ( !(a % 5) )  line ( x1 - 4, e, x1 + 4, e );
  165.                         if ( !(a % 10) ) line ( x1 - 5, e, x1 + 5, e );
  166.                 }
  167.         }
  168. }
  169.  
  170. void Koordinaten ( void )
  171. {
  172.         int x1, y1;
  173.         double r, i;
  174.  
  175.         setcolor ( WHITE );
  176.         rectangle ( 47, 22, x+53, y+28 );
  177.         r = rmax - rmin;
  178.         x1 = 50 + round ( ( -rmin ) * x / r );
  179.         line ( x1, 22, x1, y + 28 );
  180.         i = imax - imin;
  181.         y1 = 25 + round ( imax * y / i );
  182.         line ( 47, y1, x+53, y1);
  183.  
  184.         Einheiten (  round ( 10 * rmax ), x, r, x1, y1, 'x');
  185.         Einheiten ( -round ( 10 * rmin ), x, -r, x1, y1, 'x');
  186.         Einheiten (  round ( 10 * imax ), y, i, x1, y1, 'y');
  187.         Einheiten ( -round ( 10 * imin ), y, -i, x1, y1, 'y');
  188. }
  189. /****************** Ende von BIOMORPH.C ******************/
  190.