#include <conio.h> /* 此头函数请不要删除 */
# include"graphics.h"
# include"math.h"
void polygonc(int x0,int y0,int r,int n,float af)
{
int x,y,xs,ys,i;
float dtheta,theta;
if(n<3) return;
dtheta=6.28318/n;
theta=af*0.0174533;
xs=x0+r*cos(theta);
ys=y0+r*sin(theta);
moveto(xs,ys);
for(i=1;i<n;i++)
{
theta=theta+dtheta;
x=x0+r*cos(theta);
y=y0+r*sin(theta);
lineto(x,y);
}
lineto(xs,ys);
}
void block(int x,int y,int a,int n,int theta,int af)
{
int x0,y0,i,r;
float t1,t2,t3,f;
t1=fabs(theta*0.0174533);
t2=60*0.017;
t3=fabs((60+theta)*0.0174533);
f=sin(t2)/(sin(t1)+sin(t3));
r=a/1.732;
x0=x;
y0=y;
for(i=1;i<=n;i++)
{
polygonc(x0,y0,r,3,af);
r=r*f;af=af-theta;
}
}
main()
{
int i,j,a,length=120,n=50,theta=10, x=320,y=240;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c://tc");
cleardevice();
setbkcolor(0);
setcolor(15);
a=length;
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
x=x+a/2;
if(j%2!=0)
{
if(i==1)
{ y=y-0.288*a;
block(x,y,a,n,theta,270);
}
else
{
y=y+0.288*a;
block(x,y,a,n,theta,330);
}
}
else
{
if(i==1)
{
y=y-0.576*a;
block(x,y,a,n,theta,330);
}
else
{
y=y+0.576*a;
block(x,y,a,n,theta,270);
}
}
theta=-theta;
y=240;
}
x=320;
y=240;
}
getch();
closegraph();
}