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

2023-04-15 18:03:13   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《计算机图形学 多角形的应用--绘制五星红旗》,欢迎阅读!
多角形,五星红旗,绘制,图形,计算机

/*五星红旗*/

#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.dywdw.cn/b27d7e4c081c59eef8c75fbfc77da26925c596d1.html

相关推荐
推荐阅读