/*ZC为虚数*/
#include "glib.h"
#define KL 200
#define BOX 0.01
#define STEP 1
int sx,sy,dx=192,dy=192;
/*描绘区域*/
double x_min=-2.0,x_max=2.0,y_min=-2.0,y_max=2.0;
double x0,y0,xc=0.3,yc=0.5; /*复数常量*/
double a1,b1,a2,b2;
void coord(void)
{
a1=(x_max-x_min)/(2*dx);
b1=(x_max+x_min)/2;
a2=(y_max-y_min)/(2*dy);
b2=(y_max+y_min)/2;
}
void plot(int col)
{
putpixel(sx,-sy,col);
putpixel(-sx,sy,col);
}
void julia(void)
{
int k;
double s;
static double x[KL+1],y[KL+1];
x[0]=x0; y[0]=y0;
for (k=1;k<=KL;k++)
{
x[k]=x[k-1]*x[k-1]-y[k-1]*y[k-1]+xc; /*实部*/
y[k]=2*x[k-1]*y[k-1]+yc; /*虚部*/
s=x[k]*x[k]+y[k]*y[k];
if (s>=4.0)
return;
}
for (k=1;k<=13;k++) /*周期点数计算*/
{
if (fabs(x[KL]-x[KL-k])<BOX && fabs(y[KL]-y[KL-k])<BOX)
{
plot(k);
return;
}
}
plot(15);
}
void main()
{
ginit();
setpalette(8,14);
set0(320,200);
coord();
/*坐标轴的描画*/
setcolor(7);
rectangle(-dx,-dy,dx,dy);
for (sx=-dx+dx/4;sx<dx;sx+=dx/4)
{
setlinestyle(4,0x1111,1);
line(sx,-dy,sx,dy);
}
for (sy=-dy+dy/4;sy<dy;sy+=dy/4)
{
setlinestyle(4,0x1111,1);
line(-dx,sy,dx,sy);
}
for (sx=0;sx<=dx;sx+=STEP)
{
x0=a1*sx+b1; /*x的初值*/
for (sy=-dy;sy<=dy;sy+=STEP)
{
y0=a2*sy+b2; /*y的初值*/
julia();
}
}
/*描画区域的显示*/
printf("\nx_min =%51.f\n",x_min);
printf("x_max =%5.1f\n",x_max);
printf("y_min =%5.1f\n",y_min);
printf("y_max =%5.1f\n",y_max);
/*复数的显示*/
printf("xc =%6.2f\n",sx);
printf("yc =%6.2f\n",yc);
gend();
}