#include "graphics.h"
#include "math.h"
#define PI 3.1415926
void cayley(int n,float x0,float y0,float len,int th)
{
float x1,y1,x2,y2,x3,y3;
int th1=20,th2=20;
float scale=0.7,dtor=PI/180,sl=scale*len;
if(n==1)return;
x1=x0+len*cos(th*dtor);
y1=y0-len*sin(th*dtor);
x2=x1+sl*cos((th+th1)*dtor);
y2=y1-sl*sin((th+th1)*dtor);
x3=x1+sl*cos((th-th2)*dtor);
y3=y1-sl*sin((th-th2)*dtor);
line(x0,y0,x1,y1);
line(x1,y1,x2,y2);
line(x1,y1,x3,y3);
cayley(n-1,x1,y1,sl,th+th1);
cayley(n-1,x1,y1,sl,th-th2);
} main()
{
float x=320.0,y=470.0;
int th=90,len=120;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
setcolor(GREEN);
cayley(2,x,y,len,th);
getch();
cayley(3,x,y,len,th);
getch();
cayley(5,x,y,len,th);
getch();
cayley(10,x,y,len,th);
getch();
cayley(15,x,y,len,th);
getch();
closegraph();
}