五星红旗用计算机图形学画,计算机图形学多角形的应用--绘制五星红旗.doc

计算机图形学多角形的应用--绘制五星红旗

/*五星红旗*/#include"graphics.h"#include"math.h"#define PI 3.1415926void 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;}运行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值