C语言图形程序设计报告.docx
《C语言图形程序设计报告.docx》由会员分享,可在线阅读,更多相关《C语言图形程序设计报告.docx(23页珍藏版)》请在冰豆网上搜索。
C语言图形程序设计报告
大连东软信息学院
电子工程系
2015级本科
C语言图形程序设计报告
系所:
电子工程系
专业:
通信工程
学生姓名:
汤程皓
学生学号:
完成日期:
2015年12月
大连东软信息学院
DalianNeusoftUniversityofInformation
C语言图形程序设计主要内容包括图形模式的初始化、基本图形功能、图形窗口以及图形模式下的文本输出等图形函数的使用,以及按键处理和声音等。
学生根据C语言图形程序设计指导书,通过编辑、编译、调试、运行示例代码,逐步掌握C语言图形应用程序中常用函数的作用及使用方法,并综合运用《C语言程序设计》课程所学知识,设计、实现具有创新功能的程序。
成果物是一个综合性较好的图形应用程序和项目报告。
1设计要求
设计并实现一个独特的图形应用程序。
要求程序功能完整;包含屏幕颜色设置、图形绘制及填充、图形窗口设置、图形模式下文本输出、按键操作等;用户界面友好;代码量500行以上。
2程序功能
使用if,for,switch,circle,line,arc及另外一些图形化编程函数实现一些画面效果(形状颜色变化,字体颜色大小设置等),最后使用line画线的方法画出中文“再见“二字。
3核心算法
大量使用for循环,switch、if判断来实现一些画面的变化;大量使用函数调用的方式来保持代码的整洁;使用delay()函数来延迟两幅画面切换的时间;大量使用图形化编程的函数和方法来实现画面效果。
注:
流程图无能为力了,不会画。
4程序代码
#include
#include
#include
#include
/*模块化编程*/
/*函数调用*/
voidstart();
voidtuoyuan();
voidguochang();
voidkaitou();
voidhuaban();
voidtree();
voidmoon();
voidend();
voidzai();
voidjian();
main()
{
intgdriver;
intgmode;
inti;
intline;
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);
}
/*开头过渡*/
voidstart()
{
intgd;
intgm;
gd=DETECT;
initgraph(&gd,&gm,"C:
\\TC20\\BGI");
randomize();
cleardevice();
setbkcolor(3);
setcolor(4);
settextstyle(0,0,2);
outtextxy(100,160,"\t\t\t\tAREYOUREADY?
!
");
settextstyle(0,0,2);
outtextxy(100,240,"Inputanykey,let'sgo!
");
}
/*画一些形状颜色渐变椭圆*/
voidtuoyuan()
{
intx=360;
inty=160;
intdriver;
intmode=VGAHI;
intnum=20;
inti;
intt;
intb;
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;
}
}
/*画变色圆周运动*/
voidguochang()
{
intgdriver;
inti;
intb;
intc;
intgmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"C:
\\TC20\\BGI");
setbkcolor(13);
for(c=1;c<9;c++)
{
switch(c){
case1:
for(i=1;i<640;i++)
{
if(i==1)
{
setcolor(14);
for(b=1;b<240;b++)
line(320,240,1,b);
}
else{}
}
break;
case2:
for(i=1;i<640;i++)
{
if(i==1)
{
setcolor(4);
for(b=240;b<480;b++)
line(320,240,1,b);
}
else{}
}
break;
case3:
for(i=1;i<640;i++)
{
if(i<320&&i>1)
{
setcolor(6);
line(320,240,i,479);
}
else{}
}
break;
case4:
for(i=1;i<640;i++)
{
if(i<640&&i>=320)
{
setcolor(5);
line(320,240,i,479);
}
else{}
}
break;
case5:
for(i=640;i>0;i--)
{
if(i==639)
{
setcolor(10);
for(b=480;b>240;b--)
line(320,240,639,b);
}
else{}
}
break;
case6:
for(i=640;i>0;i--)
{
if(i==639)
{
setcolor(3);
for(b=240;b>0;b--)
line(320,240,639,b);
}
else{}
}
break;
case7:
for(i=640;i>0;i--)
{
if(i<640&&i>=320)
{
setcolor(9);
line(320,240,i,1);
}
else{}
}
break;
case8:
for(i=640;i>0;i--)
{
if(i<320&&i>0)
{
setcolor(12);
line(320,240,i,1);
}
else{}
}
break;
}
}
}
/*开头*/
voidkaitou()
{
inti;
inta;
intb;
intc;
intgdriver;
intgmode;
chars[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,"DREAMSTART!
");
setcolor(14);
settextstyle(3,0,2);
outtextxy(120,200,"Pleaseinputanykey!
");
getch();
closegraph();
return0;
}
/*用math画颜色变化花瓣*/
voidhuaban()
{
floata,e;
floatx1,y1,x2,y2;
intgdriver=DETECT,b;
intgmode;
initgraph(&gdriver,&gmode,"C:
//TC20//BGI");
cleardevice();
setcolor(GREEN);
setbkcolor(0);
for(b=1;b<6;b++)
{
switch(b){
case1:
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;
case2:
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;
case3:
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;
case4:
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;
case5:
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;
}
}
}
/*画树*/
voidtree()
{
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);
}
/*画月亮*/
voidmoon()
{
setcolor(14);
circle(570,70,40);
setfillstyle(1,14);
floodfill(570,70,14);
}
/*倒数第二结尾,过渡*/
voidend()
{
intgdriver;
intgmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"C:
//TC20//BGI");
setbkcolor(3);
setcolor(4);
settextstyle(0,0,6);
outtextxy(90,200,"THEEND!
");
setusercharsize(10,1,4,1);
settextstyle(3,0,2);
outtextxy(220,380,"Pleaseinputanykey!
");
getch();
}
/*正式结尾*/
/*用横线拼出“再”*/
voidzai()
{
inta,b,c,d,e,f,g,h,gdriver;
intgmode;
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);
line(177.5,g,192.5,g);
g+=1;
}
for(h=243;h<=280;)
{
setcolor(14);
line(h,335,h,350);
h+=1;
}
jian();
getch();
}
/*用横线拼出“见”,并署名*/
voidjian()
{
inta,b,c,d,e,f,g;
for(a=380;a<555;)
{
setcolor(14);
line(a,55,a,70);
a+=1;
}
for(b=55;b<250;)
{
setcolor(14);
line(380,b,395,b);
b+=1;
}
for(c=55;c<250;)
{
setcolor(14);
line(540,c,555,c);
c+=1;
}
for(d=220;d<=350;)
{
setcolor(14);
line(486,d,501,d);
d+=1;
}
for(e=486;e<612;)
{
setcolor(14);
line(e,335,e,350);
e+=1;
}
for(f=280;f<=350;)
{
setcolor(14);
line(597,f,612,f);
f+=1;
}
for(g=160;g<=175;)
{
setcolor(14);
arc(g,90,-90,0,300);
g+=1;
}
settextstyle(1,0,1);
outtextxy(335,420,"TCHwaswrittenin2015-12-12");
}
5运行结果
开头
开头过渡
一些颜色形状渐变椭圆
颜色渐变同心圆
颜色按顺序变化花瓣+树+月亮
结尾过渡
结尾
6创新说明
使用for循环语句画出一些形状颜色渐变的椭圆和同心圆;在椭圆里面画圆,并填充颜色,来实现眼睛的效果;使用switch,if判断,和for循环来实现颜色如风车般变化的动画;使用switch判断,for循环和line、数学函数来实现颜色变化的花瓣图案;使用for循环,line函数,计算坐标的方式来画出中文“再见”二字;
参考文献
[1]全球最大中文IT社区.TurboC图形函数[EB/OL],,2005.3
[2]《C语言图形程序设计指导书》