Программа для построения множеств Жюлиа
#include
<stdio.h>
#include <dos.h>
#include <conio.h>
#include
<stdlib.h>
#include
"256.с"
#define M 1000
#define A 320
#define B 200
#define K 192
#define UP 72
#define RIGHT 77
#define DOWN 80
#define LEFT 75
#define ESC 27
#define SPACE 32
typedef struct
{
unsigned
char red,green,blue;
}
RGB;
RGB pal[256];
void
swap(void)
{ RGB
t;
int
i;
t=pal[192];
for
(i=192;i>=2;--) pal[i]=pal[i-1] ;
pal[1]=t;
SetVgaDAC (FP_SEG (pal),FP_OFF(pal)) ;
}
void
draw(float Pmin,float Pmax,float Qmin,float Qmax,float p0,float q0)
{ int
x,y,color,k;
float xk,yk,t,r,DP=((Pmax-Pmin)/(A-1)),DQ=((Qmax-Qmin)/(B-1)) ;
for (x=0;x<320;x++)
for (y=0;y<200;y++)
{ xk=Pmin+x*DP;
yk=Qmin+y*DQ;
k=0;
do
{ t=xk;
xk=xk*xk-yk*yk+p0;
yk=2*t*yk+q0;
r=xk*xk+yk*yk;
k++;
} while ((k<K)&&(r<M)) ;
if (r>M) color=k;
if (k==K) color=0;
putpixel256(x,y,color);
}
}
void main(void)
{
int i,j,x,y,par;
float Pmin=-l,Pmax=l,Qmin=-l,Qmax=l,P0=0.3,Q0=0.6;
int key,newpar,cycl;
set256();
pal[0].red=pal[0].green=pal[0].blue=0;
for (x=l;x<=64;x++)
{ pal[x].red=64-x;
pal[x].green=x-l;
pal[x].blue=0;
pal[64+x].red=0;
pal[64+x].green=64-x;
pal[64+x].blue=x-l;
pal[128+x].red=x-l;
pal[128+x].green=0;
pal[128+x].blue=64-x;
}
SetVgaDAC(FP_SEG(pal),FP_OFF(pal));
newpar=l;cycl=0 ;
for (i=0;l;i=(i+l)%par)
{
if (newpar) draw(Pmin,Pmax,Qmin,Qmax,P0,Q0);
if (cycl) swap() ;
if (kbhit())
{ newpar=l;
key=getch() ;
if (key==ESC) break;
if (key==SPACE) {newpar=0;cycl=!cycl;}
if (!key)
{ key=getch() ;
switch (key)
{
case UP: Q0+=0.005;break;
case DOWN: Q0-=0.005;break;
case LEFT: P0-=0.005;break;
case RIGHT: P0+=0.005;break;
}
}
}
else newpar=0;
}
setTEXT() ;
}