C語(yǔ)言繪圖教程例子5-1
代碼
#include <graphics.h>
#include <math.h>
void polygon(x0,y0,a,n,af)
int x0,y0,a,n;
float af;
{
int x,y,i;
float dtheta,theta;
if(n<3) return;
dtheta=6.28318/n;
theta=af*0.0174533;
moveto(x0,y0);
x=x0;
y=y0;
for(i=1;i<n;i++)
{
x=x+a*cos(theta);
y=y+a*sin(theta);
lineto(x,y);
theta=theta+dtheta;
}
lineto(x0,y0);
}
int main()
{
int i,a=80,x=200,y=100;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c\\tc");
cleardevice();
setbkcolor(9);
setcolor(4);
for(i=3;i<=10;i++)
polygon(x,y,a,i,0);
getch();
return 0;
}運(yùn)行

*博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。

