#include "glib.h"
int N=12; /*递归次数*/
double sx=120.0,sy=240.0; /*开始点坐标*/
double leng0=400.0; /*开始点与结束点的距离*/
double a,b,t=0.57735;
void fractal(double x0,double y0,double x1,double y1,int n) /*分形图形描画函数*/
{
double px,py;
if (n<=N)
{
px=x0+(a*(x1-x0)-b*pow(-1.0,(double)n-1)*(y1-y0));
py=y0+(b*pow(-1.0,(double)n-1)*(x1-x0)+a*(y1-y0));
putpixel(px,-py,15);
fractal(x0,y0,px,py,n+1);
fractal(px,py,x1,y1,n+1);
}
}
void main()
{
ginit();
set0(sx,sy);
a=1.0/2;
b=t/2;
putpixel(0,0,9); /*描画开始点*/
putpixel(leng0,0,12); /*描画结束点*/
fractal(0.0,0.0,leng0,0.0,1);
gend();
}