【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《计算机图形学 多角形的应用--绘制五星红旗》,欢迎阅读!
/*五星红旗*/
#include"graphics.h" #include"math.h" #define PI 3.1415926 void poly1(); main() {
int n=5,x0,y0,r; float af;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode," "); cleardevice(); setbkcolor(RED); setcolor(YELLOW); moveto(30,50); lineto(606,50); lineto(606,434); lineto(30,434); lineto(30,50);
setfillstyle(SOLID_FILL,YELLOW); floodfill(1,1,YELLOW);
x0=30+5*19.2; y0=50+5*19.2; r=3*19.2; af=55;
poly1(x0,y0,r,n,af);
setfillstyle(SOLID_FILL,YELLOW); floodfill(x0,y0,YELLOW);
x0=30+10*19.2; y0=50+2*19.2; r=19.2; af=3;
poly1(x0,y0,r,n,af);
setfillstyle(SOLID_FILL,YELLOW); floodfill(x0,y0,YELLOW);
x0=30+12*19.2; y0=50+4*19.2; r=19.2; af=29;
poly1(x0,y0,r,n,af);
setfillstyle(SOLID_FILL,YELLOW); floodfill(x0,y0,YELLOW);
x0=30+12*19.2; y0=50+7*19.2; r=19.2;
af=50;
poly1(x0,y0,r,n,af);
setfillstyle(SOLID_FILL,YELLOW); floodfill(x0,y0,YELLOW);
x0=30+10*19.2; y0=50+9*19.2; r=19.2; af=78;
poly1(x0,y0,r,n,af);
setfillstyle(SOLID_FILL,YELLOW); floodfill(x0,y0,YELLOW);
getch();
closegraph(); }
void poly1(x0,y0,r,n,af) int x0,y0,n,r; float af; {
int i;
float th,af1,ct,st,ca,sa,xs,ys,cc,ss,x,y,r1,rr; if(n<=4) return;
th=3.1415926/n; af1=af*0.0174533; ct=cos(th); st=sin(th); ca=cos(af1); sa=sin(af1); xs=x0+r*ca; ys=y0+r*sa; moveto(xs,ys);
r1=r*sin((n-4)*th/2)/sin((n-2)*th/2); for(i=1;i<2*n;i++) {
cc=ca; ss=sa;
ca=cc*ct-ss*st; sa=ss*ct+cc*st; rr=r;
if(i-i/2*2==1) rr=r1; x=x0+rr*ca; y=y0+rr*sa; lineto(x,y); }
lineto(xs,ys); return;
本文来源:https://www.wddqxz.cn/b27d7e4c081c59eef8c75fbfc77da26925c596d1.html