大连东软信息学院
电子工程系
2015级本科
C语言图形程序设计报告
系所:电子工程系
专业:通信工程
学生姓名:汤程皓
学生学号:151********
完成日期:2015 年12 月
大连东软信息学院
Dalian Neusoft University of Information
目录
目录 ..............................................................................................................................................- 1 -
1 设计要求...................................................................................................................................-
2 -
2 程序功能...................................................................................................................................- 2 -
3 核心算法...................................................................................................................................- 2 -
4 程序代码...................................................................................................................................- 2 -
5 运行结果................................................................................................................................ - 22 -
6 程序创新说明........................................................................................................................ - 28 -参考文献.................................................................................................................................... - 28 -
C语言图形程序设计主要内容包括图形模式的初始化、基本图形功能、图形窗口以及图形模式下的文本输出等图形函数的使用,以及按键处理和声音等。学生根据C语言图形程序设计指导书,通过编辑、编译、调试、运行示例代码,逐步掌握C语言图形应用程序中常用函数的作用与使用方法,并综合运用《C 语言程序设计》课程所学知识,设计、实现具有创新功能的程序。成果物是一个综合性较好的图形应用程序和项目报告。
1 设计要求
设计并实现一个独特的图形应用程序。要求程序功能完整;包含屏幕颜色设置、图形绘制与填充、图形窗口设置、图形模式下文本输出、按键操作等;用户界面友好;代码量500行以上。
2 程序功能
使用if,for,switch,circle,line,arc及另外一些图形化编程函数实现一些画面效果(形状颜色变化,字体颜色大小设置等),最后使用line画线的方法画出中文“再见“二字。
3 核心算法
大量使用for循环,switch、if判断来实现一些画面的变化;大量使用函数调用的方式来保持代码的整洁;使用delay()函数来延迟两幅画面切换的时间;大量使用图形化编程的函数和方法来实现画面效果。
注:流程图无能为力了,不会画。
4 程序代码
#include
#include
#include
#include
/*模块化编程*/
/*函数调用*/
void start();
void tuoyuan();
void guochang();
void kaitou();
void huaban();
void tree();
void moon();
void end();
void zai();
void jian();
main()
{
int gdriver;
int gmode;
int i;
int line;
clrscr();
gdriver=DETECT;
initgraph(&gdriver,&gmode,"C:\\TC20\\BGI");
kaitou();
start();
getch();
tuoyuan();
delay(800);
setbkcolor(15);
cleardevice();
/*插入眼睛像*/
ellipse(320,240,0,360,30,17.5); setcolor(4);
circle(320,240,17.5); setfillstyle(1,4);
floodfill(320,240,4);
/*画颜色渐变同心圆*/
for(i=0;i<=30;i++)
{
setcolor(i);
circle(320,240,20+i*10);
delay(80);
}
delay(800);
guochang();
delay(1000);
cleardevice();
huaban();
moon();
tree();
delay(500);
cleardevice();
end();
setbkcolor(6);
zai();
delay(1000);
}
/*开头过渡*/
void start()
{
int gd;
int gm;
gd=DETECT;
initgraph(&gd,&gm,"C:\\TC20\\BGI");
randomize();
cleardevice();
setbkcolor(3);
setcolor(4);
settextstyle(0,0,2);
outtextxy(100,160," \t\t\t\t ARE YOU READY?!");
settextstyle(0,0,2);
outtextxy(100,240," Input any key,let's go!");
}
/*画一些形状颜色渐变椭圆*/
void tuoyuan()
{
int x=360;
int y=160;
int driver;
int mode=VGAHI;
int num=20;
int i;
int t;
int b;
driver=DETECT;
initgraph(&driver,&mode,"C://TC20//BGI");
t=y-30;
b=y-30;
setbkcolor(0);
for(i=0;i { setcolor(i+2-1); ellipse(200,230,0,360,t,b); t-=5; b+=5; } delay(300); for(i=0;i<20;i++) { setcolor(i+2-1); ellipse(470,240,0,360,t,b); t+=5; b-=5; } } /*画变色圆周运动*/ void guochang() { int gdriver; int i; int b; int c; int gmode; gdriver=DETECT; initgraph(&gdriver,&gmode,"C:\\TC20\\BGI"); setbkcolor(13); for(c=1;c<9;c++) { switch(c){ case 1:for(i=1;i<640;i++) { if(i==1) { setcolor(14); for(b=1;b<240;b++) line(320, 240, 1, b); } else{} } break; case 2:for(i=1;i<640;i++) { if(i==1) { setcolor(4); for(b=240;b<480;b++) line(320,240,1,b); } else{} } break; case 3:for(i=1;i<640;i++) { if(i<320&&i>1) { setcolor(6); line(320,240,i,479); } else{} } break; case 4:for(i=1;i<640;i++) { if(i<640&&i>=320) { setcolor(5); line(320, 240, i,479); } else{} } break; case 5:for(i=640;i>0;i--) { if(i==639) { setcolor(10); for(b=480;b>240;b--) line(320,240,639,b); } else{} } break; case 6:for(i=640;i>0;i--) { if(i==639) { setcolor(3); for(b=240;b>0;b--) line(320, 240,639, b); } else{} } break; case 7:for(i=640;i>0;i--) { if(i<640&&i>=320) { setcolor(9); line(320,240,i,1); } else{} } break; case 8:for(i=640;i>0;i--) { if(i<320&&i>0) { setcolor(12); line(320, 240, i, 1); } else{} } break; } } } /*开头*/ void kaitou() { int i; int a; int b; int c; int gdriver; int gmode; char s[30]; clrscr(); gdriver=DETECT; initgraph(&gdriver, &gmode, "C:\\TC20\\BGI"); setbkcolor(14); cleardevice(); for(a=50;a<640;) { b=50; setcolor(4); circle(a,b,43); setcolor(9); ellipse(a,b,0,360,43,20); ellipse(a,b,0,360,20,43); setcolor(7); ellipse(a,b,0,360,20,10); setcolor(8); circle(a,b,10); setfillstyle(1,8); floodfill(a,b,8); a=a+90; } for(b=50;b<480;) { a=50; setcolor(4); circle(a,b,45); setcolor(9); ellipse(a,b,0,360,21,45); ellipse(a,b,0,360,45,21); setcolor(7); ellipse(a,b,0,360,22.5,12); circle(a,b,12); b=b+95; } for(a=50;a<640;) { b=430; setcolor(4); circle(a,b,43); setcolor(9); ellipse(a,b,0,360,43,20); ellipse(a,b,0,360,20,43); setcolor(7); ellipse(a,b,0,360,20,10); circle(a,b,10); a=a+90; } for(b=50;b<480;) { a=590; setcolor(4); circle(a,b,45); setcolor(9); ellipse(a,b,0,360,21,45); ellipse(a,b,0,360,45,21); setcolor(7); ellipse(a,b,0,360,22.5,12); circle(a,b,12); b=b+95; } setviewport(100, 100, 540, 380, 0); setfillstyle(1, 2); setcolor(14); rectangle(0, 0, 439, 279); floodfill(50, 50, 14); setcolor(12); settextstyle(4, 0, 8); outtextxy(20, 20, "TCH"); setcolor(15); settextstyle(3, 0, 5); outtextxy(120, 120, "DREAM START!"); setcolor(14); settextstyle(3, 0, 2); outtextxy(120, 200, "Please input any key!"); getch(); closegraph(); return 0; } /*用math画颜色变化花瓣*/ void huaban() { float a,e; float x1,y1,x2,y2; int gdriver=DETECT,b; int gmode; initgraph(&gdriver,&gmode,"C://TC20//BGI"); cleardevice(); setcolor(GREEN); setbkcolor(0); for(b=1;b<6;b++) { switch(b){ case 1:for(a=0.0;a<2*3.14;a+=2*3.14/720) { e=100*(1+sin(4*a)); x1=320+e*cos(a); x2=320+e*cos(a+3.14/5); y1=240+e*sin(a); y2=240+e*sin(a+3.14/5); setcolor(10); line(x1,y1,x2,y2); }break; case 2:for(a=0.0;a<2*3.14;a+=2*3.14/720) { e=100*(1+sin(4*a)); x1=320+e*cos(a); x2=320+e*cos(a+3.14/5); y1=240+e*sin(a); y2=240+e*sin(a+3.14/5); setcolor(12); line(x1,y1,x2,y2); }break; case 3:for(a=0.0;a<2*3.14;a+=2*3.14/720) { e=100*(1+sin(4*a)); x1=320+e*cos(a); x2=320+e*cos(a+3.14/5); y1=240+e*sin(a); y2=240+e*sin(a+3.14/5); setcolor(14); line(x1,y1,x2,y2); }break; case 4:for(a=0.0;a<2*3.14;a+=2*3.14/720) { e=100*(1+sin(4*a)); x1=320+e*cos(a); x2=320+e*cos(a+3.14/5); y1=240+e*sin(a); y2=240+e*sin(a+3.14/5); setcolor(1); line(x1,y1,x2,y2); }break; case 5:for(a=0.0;a<2*3.14;a+=2*3.14/720) { e=100*(1+sin(4*a)); x1=320+e*cos(a); x2=320+e*cos(a+3.14/5); y1=240+e*sin(a); y2=240+e*sin(a+3.14/5); setcolor(9); line(x1,y1,x2,y2); }break; } } } /*画树*/ void tree() { setcolor(8); line(80,400,80,440); line(80,440,75,447); line(75,447,91,447); line(91,447,86,440); line(86,440,86,400); line(86,400,80,400); setfillstyle(6,8); floodfill(83,410,8); setcolor(2); line(83,330,55,400); line(55,400,111,400); line(111,400,83,330); setfillstyle(1,2); floodfill(60,390,2); line(83,290,55,360); line(55,360,111,360); line(111,360,83,290); setfillstyle(1,2); floodfill(80,310,2); delay(1000); } /*画月亮*/ void moon() { setcolor(14); circle(570,70,40); setfillstyle(1,14); floodfill(570,70,14); } /*倒数第二结尾,过渡*/ void end() { int gdriver; int gmode; gdriver=DETECT; initgraph(&gdriver,&gmode,"C://TC20//BGI"); setbkcolor(3); setcolor(4); settextstyle(0,0,6); outtextxy(90,200," THE END!"); setusercharsize(10,1,4,1); settextstyle(3, 0, 2); outtextxy(220, 380, "Please input any key!"); getch(); } /*正式结尾*/ /*用横线拼出“再”*/ void zai() { int a,b,c,d,e,f,g,h,gdriver; int gmode; gdriver=DETECT; initgraph(&gdriver,&gmode,"C://TC20//BGI"); for(a=70;a<300;) { setcolor(14); line(a,55,a,70); a=a+1; } for(b=120;b<350;) { setcolor(14); line(90,b,105,b); b=b+1; } for(c=90;c<280;) { setcolor(14); line(c,120,c,135); c=c+1; } for(d=120;d<350;) { setcolor(14); line(265,d,280,d); d=d+1; } for(e=105;e<265;) { setcolor(14); line(e,180,e,195); e+=1; } for(f=45;f<325;) { setcolor(14); line(f,240,f,255); f+=1; } for(g=70;g<=255;) { setcolor(14);