Category : Printer + Display Graphics
Archive   : DKMANDEL.ZIP
Filename : MANDL_87.C

 
Output of file : MANDL_87.C contained in archive : DKMANDEL.ZIP

/* Module name: mandel.c
** Purpose: Calculate & display the Mandelbrot set and closeups.
** Author: Doug Klein (based on example set by Thomas Salem)
** Data line: IBM *West* BBS 1200/2400(402)896-1555 running RBBS-13
** BIX Name: daklein
** Compiler: Turbo C version 1.0
** Coding Style: straight-line (its too small to do functional splits)
** Machine: AT&T PC6300
** Reference: The Beauty of Fractals
** (Images of Complex Dynamical Systems)
** by H.-O.Pietgen & P.H.Richter
** Revisions: 9 January 1988 - initial release.
** 4 February 1988 - [modified by Jim Bayer,
** EDGE BBS, 402-554-8488.]
** 1 May 1988 - combine CRTs' modes
**
**/
#include
#include
/*
global function declarations
*/
int getch(),kbhit();
void exit();
union REGS inregs, outregs;
main()
{
float m,x0,y0,xnew,pmin,pmax,qmin,qmax,delq,delp,p0,q0,r;
int a, b,color,j,k,l,kmax,kulrs,choz_mode,mode,z;
int pk[480], pp;
/******* let monitor have 'a' times 'b' points ******/
printf(" c-Plane Pictures: Mandelbrot Set and Close-Ups\n\n");
printf("Map_______|__________Re c______________|__________lm c_____________\n");
printf(" | max p min p | max q min q \n");
printf("__________|____________________________|___________________________\n");
printf("26 | 0.75 ... -2.25 | 1.5 ... -1.5 \n");
printf("27,52-54 | -0.19920 ... -0.129454 | 1.06707 ... 1.01480 \n");
printf("29 | -0.95 ... -0.88333 | 0.3 ... 0.23333 \n");
printf("30________|_-0.713______..._-0.4082____|__0.71429____...__0.49216__\n");
printf("33,51 | -1.781 ... -1.764 | 0.013 ... 0.0 \n");
printf("36 | -0.75104 ... -0.7408 | 0.11536 ... 0.10511 \n");
printf("38 | -0.74758 ... -0.74624 | 0.10779 ... 0.10671 \n");
printf("40________|_-0.746541___..._-0.746378__|__0.107678___...__0.107574_\n");
printf("42,100,101| -0.74591 ... -0.74448 | 0.11339 ... 0.11196 \n");
printf("44,46,99 | -0.745538 ... -0.745054 | 0.113236 ... 0.112881 \n");
printf("45,47 | -0.745468 ... -0.745385 | 0.113039 ... 0.112979 \n");
printf("48,50_____|_-0.7454356__..._-0.7454215_|__0.1130139__...__0.1130037\n");
printf("49 | -0.7454301 ... -0.7454289 | 0.1130085 ... 0.1130076\n");
printf("58-60 | -1.254024 ... -1.252861 | 0.047125 ... 0.046252 \n");
printf("-------------------------------------------------------------------\n\n");
/**/
printf("Input max p: "); scanf("%f",&pmax);
printf("Input min p: "); scanf("%f",&pmin);
printf("Input max q: "); scanf("%f",&qmax);
printf("Input min q: "); scanf("%f",&qmin);
printf("Input max k [# iterations (150 to 10000)] : "); scanf("%d",&kmax);
/**/
do
{
printf("Input CRT type:\n\t(1)CGA 320x200 4 color\t\t(2)CGA 640x200b/w");
printf("\n\t(3) AT&T 640x400 b/w\t\t(4) EGA 640x350 16 colors\n");
printf("\n\t(5) VGA 640x480 16 colors\t(6) VGA 320x200 256 colors.");
printf("\n\t...? ");
scanf("%d",&choz_mode);
switch (choz_mode)
{
case 1: mode = 5; a = 320; b = 200; kulrs = 4;
break;
case 2: mode = 6; a = 640; b = 200; kulrs = 2;
break;
case 3: mode = 0x48; a = 640; b = 400; kulrs = 2;
break;
case 4: mode = 0x10; a = 640; b = 350; kulrs = 16;
break;
case 5: mode = 18; a = 640; b = 480; kulrs = 16;
break;
case 6: mode = 19; a = 320; b = 200; kulrs = 256;
break;
}
}
while((choz_mode < 1) || (choz_mode > 6));
inregs.h.ah = 0; /******* set video mode *********/
inregs.h.al = mode;
int86(0x10, &inregs, &outregs);
m = 200.0;
/******* set delta p & delta q *********/
delp = (pmax - pmin) / (a - 1);
delq = (qmax - qmin) / (b - 1);
/******* get started *************/
for (l = 0; l <= (a - 1); l++ )
{
for ( j = 0; j <= (b - 1); j++ )
{
if( (kbhit() != 0) && (getch() == 0x03) )
{
inregs.h.ah = 0; /**** reset video mode ***/
inregs.h.al = 3;
int86(0x10, &inregs, &outregs);
exit(1);
}
p0 = pmin + l * delp;
k = 0;
x0 = 0.0;
y0 = 0.0;
q0 = qmin + j * delq;
r = 0;
while ( (r <= m) && (k < kmax) )
{
xnew = x0*x0 - y0*y0 + p0;
y0 = 2.0*x0*y0 + q0;
x0 = xnew;
r = x0*x0 + y0*y0;
k++;
} /* while */
z = 0;
color = 0;
while ( z <= kmax )
{
if ( k <= (z*10) )
{
color = z;
z = kmax+1;
} /* if */
z++ ;
} /* while */
if (color != kmax)
{
pk[j] = (color % kulrs);
}
} /* for */
for ( pp = 0; pp <= (b - 1); pp++ )
{
inregs.h.ah = 12;
inregs.h.al = pk[pp];
inregs.x.cx = l; /** y **/
inregs.x.dx = pp; /** x **/
int86(0x10, &inregs, &outregs);
} /* for */

} /* for */
/**** beep & wait for any key ****/
printf("\007");

getch();
printf("\007");
getch();
printf("\007");
getch();
/**** reset video mode before exiting ***/
inregs.h.ah = 0;
inregs.h.al = 3;
int86(0x10, &inregs, &outregs);
} /* main */