#include #include #include #include float sa,x,y,scale,branch; void linetheta(float ang,double l,float *x, float *y) { float rad=3.14159/180, k1, k2; k1=l*cos(rad*ang); k2=l*sin(rad*ang); line(*x,*y,*x+k1,*y+k2); *x+=k1; *y+=k2; } void tree(int n, float xx, float yy, float leng ,float ang) { if (n == 0) return ; x=xx; y=yy; sa=ang; linetheta(ang,leng,&x,&y); xx=x; yy=y; tree(n-1,xx,yy,leng/scale,ang-branch); tree(n-1,xx,yy,leng/scale,ang+branch); } void main() { int Driver, Mode, n, k; /* The Graphics device driver */ struct point { int x,y; } p1; double rr; p1.x=200, p1.y=150; rr=100.0; k=6; sa=60.0; scale=1.212; branch=20.0; /* branch degree */ Driver = DETECT; /* Request auto-detection */ initgraph( &Driver, &Mode, "" ); sa=0; setcolor(14); x=p1.x; y=p1.y; moveto(x,y); tree(k,x,y,rr,sa); getche(); closegraph(); /* Return the system to text mode */ }