home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************/
- /* */
- /* BIOMORPH */
- /* Ein Programm zur Erzeugung von sog. 'Biomorphen' nach */
- /* C. A. Pickover, beschrieben von A. K. Dewdney in */
- /* 'Spektrum der Wissenschaft', Sonderheft 10, S. 60 ff. */
- /* */
- /* Dient zur Demonstration der INCLUDE-Datei 'complex.c' */
- /* */
- /* Sprache: Turbo C 2.0 */
- /* (C) 1991 Ralf Baethke-Franke & toolbox */
- /* */
- /**********************************************************/
-
- #include <graphics.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <dos.h>
- #include "complex.c"
-
- /* Globale Variable */
-
- compl z,z0,c;
- int j,k,n,iter,farben;
- float rmin,rmax,imin,imax;
- int funktion;
- int xasp,yasp,x,y;
-
- /* Funktionsprototypen */
-
- void Rechnen ( void );
- void main ( void );
- void Eingabe ( void );
- void Grafik ( void );
- int round ( double v );
- void Einheiten ( int g, double b, double c, int x1,
- int y1, char achse );
- void Koordinaten ( void );
-
- /* Funktionen */
-
- void Rechnen ( void )
- {
- z = sqr_c(z);
- }
-
- void main ( void )
- {
- double a,b;
-
- Eingabe ();
- sound ( 1000 ); delay ( 10 ); nosound ();
- Grafik ();
- Koordinaten ();
- a = ( rmax - rmin ) / x;
- b = ( imax - imin ) / y;
- for ( j = 0; j < x; j++ )
- {
- for ( k = 0; k < y; k++ )
- {
- z0.re = rmin + a * j;
- z0.im = imin + b * k;
- z = z0;
- for ( n = 1; n < iter + 1; n++)
- {
-
- if ( kbhit () != 0 )
- {
- if ( getch () == 27 )
- {
- restorecrtmode ();
- exit ( 0 );
- }
- }
- Rechnen ();
- z = add_c ( z, c );
-
- if ( abs ( z.re ) > 10 || abs ( z.im ) > 10 )
- break;
- }
- if ( abs ( z.re ) < 10 || abs ( z.im ) < 10 )
- {
- while ( n > farben ) n -= farben;
- if ( n == farben ) n -= 1;
- if ( getpixel ( j + 50, y + 25 - k ) != WHITE )
- putpixel ( j + 50, y + 25 - k, n );
- }
- }
- }
- sound ( 2000 ); delay ( 500 ); nosound ();
- getch ();
- }
-
- void Eingabe ( void )
- {
- float c1;
-
- clrscr ();
- gotoxy ( 32, 1 );
- highvideo ();
- cprintf ( "B I O M O R P H" );
- gotoxy ( 32, 2 );
- cprintf ( "===============" );
- lowvideo ();
- printf ( "\n\nUntere Grenze für die reelle Achse : " );
- scanf ( "%f", &rmin );
- printf ( "Obere Grenze für die reelle Achse : " );
- scanf ( "%f", &rmax );
- printf ( "Untere Grenze für die imaginäre Achse: " );
- scanf ( "%f", &imin );
- imax = imin + ( rmax - rmin );
- printf ( "Obere Grenze für die imaginäre Achse : %.2f\n",
- imax );
- printf ( "\nRealteil der Konstante : " );
- scanf ( "%f", &c1 );
- c.re = c1;
- printf ( "Imaginärteil der Konstante: " );
- scanf ( "%f", &c1 );
- c.im = c1;
- printf ( "\nAnzahl Iterationen: " );
- scanf ( "%d", &iter );
- }
-
- void Grafik ( void )
- {
- int gd, gm;
-
- detectgraph ( &gd, &gm );
- initgraph ( &gd, &gm, "" );
- getaspectratio ( &xasp, &yasp );
- y = getmaxy () - 50;
- x = (int) ( ( long ) y * ( long ) yasp / ( long ) xasp );
- farben = getmaxcolor () + 1;
- }
-
- int round ( double v )
- {
- return ( floor ( v + 0.5 ) );
- }
-
- void Einheiten ( int g, double b, double c, int x1, int y1,
- char achse)
- {
- int a, e;
-
- if (achse == 'x')
- {
- for ( a = 0; a <= g; a++)
- {
- e = x1 + round ( ( a * b ) / ( 10 * c ) );
- line ( e, y1 - 3, e, y1 + 3 );
- if ( !(a % 5) ) line ( e, y1 - 4, e, y1 + 4 );
- if ( !(a % 10) ) line ( e, y1 - 5, e, y1 + 5 );
- }
- }
-
- if ( achse == 'y' )
- {
- for ( a = 0; a <= g; a++)
- {
- e = y1 - round ( ( a * b ) / ( 10 * c ) );
- line ( x1 - 3, e, x1 + 3, e );
- if ( !(a % 5) ) line ( x1 - 4, e, x1 + 4, e );
- if ( !(a % 10) ) line ( x1 - 5, e, x1 + 5, e );
- }
- }
- }
-
- void Koordinaten ( void )
- {
- int x1, y1;
- double r, i;
-
- setcolor ( WHITE );
- rectangle ( 47, 22, x+53, y+28 );
- r = rmax - rmin;
- x1 = 50 + round ( ( -rmin ) * x / r );
- line ( x1, 22, x1, y + 28 );
- i = imax - imin;
- y1 = 25 + round ( imax * y / i );
- line ( 47, y1, x+53, y1);
-
- Einheiten ( round ( 10 * rmax ), x, r, x1, y1, 'x');
- Einheiten ( -round ( 10 * rmin ), x, -r, x1, y1, 'x');
- Einheiten ( round ( 10 * imax ), y, i, x1, y1, 'y');
- Einheiten ( -round ( 10 * imin ), y, -i, x1, y1, 'y');
- }
- /****************** Ende von BIOMORPH.C ******************/