计算机技术基础课程设计
C语言
设计报告
题目:制作节日礼花
一、选题背景:
随着节日的到来,人们都会在节日里燃放礼花,而且礼花的样式有很多,本程序就是实现了节日礼花的制作过程,礼花的制作,然后开始绽放。展现了一个美丽的节日场景。
二、:设计思路
在这个制作节日礼花的程序里,开头是通过调用一系列的库函数,以备下面的程序使用。接着通过自定义一些函数,来说明存放礼花的位置,礼花的上升,礼花的形状,礼花的盛开等。这些自定义的函数包括一个结构体函数,定义存放礼花的位置,一个无返回值的函数定义礼花的上升等。在后面主函数中,通过调用这些自定义的函数来完成节日礼花的制作.
三、主要解决问题的方法及技术关键:
本程序应用了while循环;for循环;switch分支语句;if条件选择语句等。
四、流程图:
INIT初始化
开始
FENGMIAN
绘制界面窗口
是否按键
Y
SHAN
0
N
UP
DEFAULT
结束
2
CENG
DIAN
1
SWITCH
BOMB
五、程序清单:
#include "Conio.h"/*字符模式函数*/
#include "graphics.h"/*圆形与椭圆的综合使用*/
#include "stdio.h"
#include "stdlib.h"/*标准头文件申明*/
#include "bios.h"
#include "math.h"/*函数原代码*/
struct cir /*存放礼花的位置*/
{
int x;
int y;
}place;
void initgr(void) /* BGI初始化 */
{
int gd=DETECT,gm=0;
initgraph(&gd,&gm,"d:\\tc");
}
void up() /*礼花炮上升*/
{ int aimy;
randomize();
place.x=random(440)+100; /*设定礼花的范围*/
place.y=470;
aimy=random(300)+60;
setlinestyle(0,0,1);
setcolor(WHITE);
circle(place.x,place.y,3);
while(place.y!=aimy) /*礼花的上升过程*/
{
setcolor(BLACK);
circle(place.x,place.y,3);
place.y--;
setcolor(WHITE);
circle(place.x,place.y,3);
delay(1000);
}
setcolor(BLACK);
circle(place.x,place.y,3);
}
shan() /*礼花形状一*/
{
int j,n1,x,t1=1,y;
int p_color;
for(j=0;j<400;j++)
{
n1=rand()%2;
t1=pow(-1,n1);
x=place.x+t1*(rand()%100);
n1=rand()%2;
t1=pow(-1,n1);
y=place.y+t1*(rand()%100);
if(x<35) x=35; /*限制礼花越过窗体*/
if(x>getmaxx()-35) x=getmaxx()-35;
if(y<5) y=5;
p_color=rand()%15;
setlinestyle(0,0,3);
setcolor(p_color);
line(place.x,place.y,x,y);
delay(1000);
setcolor(BLACK);
line(place.x,place.y,x,y);
}
}
ceng() /*礼花形状二*/
{
float x,y,r;
int i;
int c_color;
float k;
k=2*3.14/60;
for(r=10;r<100;r++)
{
for(i=0;i<60;i++)
{
x=r*sin(k*i)+place.x;
y=r*cos(k*i)+place.y;
if(x<35) x=35;
if(x>getmaxx()-35) x=getmaxx()-35;
if(y<5) y=5;
c_color=rand()%15;
putpixel(x,y,c_color);
delay(80);
}
}
for(r=10;r<100;r++)
{
for(i=0;i<60;i++)
{
x=r*sin(k*i)+place.x;
y=r*cos(k*i)+place.y;
if(x<35) x=35;
if(x>getmaxx()-35) x=getmaxx()-35;
if(y<5) y=5;
putpixel(x,y,BLACK);
delay(60);
}
}
}
dian() /*礼花形状三*/
{
int i,j,r;
float x[500],y[500];
float k;
int c_color;
k=2*3.14/60;
for(j=0;j<500;j++)
{
i=rand()%60;
r=rand()%100;
x[j]=r*sin(k*i)+place.x;
y[j]=r*cos(k*i)+place.y;
if(x[j]<35) x[j]=35;
if(x[j]>getmaxx()-35) x[j]=getmaxx()-35;
if(y[j]<5) y[j]=5;
c_color=rand()%15;
setcolor(c_color);
circle(x[j],y[j],1);
delay(1500);
}
for(j=0;j<500;j++)
{
setcolor(BLACK);
circle(x[j],y[j],1);
}
}
void bomb() /*礼花盛开*/
{
int r1,i,n,t=1,q=1,k=1;
int pointX,pointY,point_color;
setcolor(YELLOW);
/*-------------这个过程模拟礼花爆炸瞬间的状态-----------------*/
for(r1=1;r1<=4;r1++)
{
circle(place.x,place.y,r1);
delay(1000);
}
delay(3000);
setcolor(RED);
for(r1=4;r1<=6;r1++)
{
circle(place.x,place.y,r1);
delay(1000);
}
delay(3000);
setcolor(BLACK);
for(r1=6;r1>=1;r1--)
{
circle(place.x,place.y,r1);
delay(1000);
}
for(i=1;i<=20;i++)
{
point_color=rand()%15;
n=rand()%2;
t=pow(-1,n);
pointX=(t*(rand()%6)+place.x);
n=rand()%2;
t=pow(-1,n);
pointY=(t*(rand()%6)+place.y);
putpixel(pointX,pointY,point_color);
delay(2000);
putpixel(pointX,pointY,BLACK);
}
/*----------------------------------------*/
n=rand()%3;
switch(n) /*随机盛开不同的厉害*/
{
case 0:
shan(); break;
case 1:
ceng(); break;
case 2:
dian(); break;
default:
break;
}
}
fengmian() /*封面程序*/
{
int i,j=0;
while(1) /**/
{
settextstyle(0,0,4); /*设置文字输出模式*/
for(i=1;i<=15;i++)
{
setcolor(i);
outtextxy(100,180,"HAPPY NEW YEAR"); /*新年快乐*/
delay(10000);
}
j++;
if(j>5) break;
}
cleardevice();
}
main()
{
initgr();
fengmian();
setbkcolor(BLACK); /*绘制窗体*/
setcolor(YELLOW);
setfillstyle(SOLID_FILL,9);
rectangle(0,0,getmaxx(),getmaxy());
rectangle(1,1,getmaxx()-1,getmaxy()-1);
rectangle(2,2,30,getmaxy()-2);
rectangle(getmaxx()-32,2,getmaxx()-2,getmaxy()-2);
while(!kbhit()) /*进入礼花程序*/
{
up();
bomb();
}
getch();
closegraph();
}
六、总结:
1、设计优点:
本程序简单明了,运用了所学的知识,一些库函数和调用,实现了节日礼花的绽放,易于操作。
2、设计缺点:
由于对知识的了解程度有限,有些功能的实现还不够简单。需要在以后的学习中不断完善
3、尚存的问题和解决办法:
学习c一段时间了,这却是第一次自己尝试着设计和编写程序,程序中的问题肯定很多,现在程序只能做到让礼花一个一个的盛开,能不能想个办法,让礼花以随机的个数,后者说是参差不齐的盛开?这个问题需要在以后的学习过程中解决。争取做出更好的程序!
展开阅读全文