c语言课程设计礼花的绽放,计算机技术基础(c语言)课程设计 制作节日礼花.doc

计算机技术基础课程设计

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一段时间了,这却是第一次自己尝试着设计和编写程序,程序中的问题肯定很多,现在程序只能做到让礼花一个一个的盛开,能不能想个办法,让礼花以随机的个数,后者说是参差不齐的盛开?这个问题需要在以后的学习过程中解决。争取做出更好的程序!

展开阅读全文

vs2017环境下成功编译,vc6.0编译不通过 #include "stdafx.h" #include #include #include #include // 使用该计时器必须包含的文件 #pragma comment ( lib, "Winmm.lib" ) using namespace std; #define LONG 800 // 窗口长 #define WIDE 500 // 窗口宽 #define NUM 13 // 烟花种类数量宏定义 void Init_Fire(); // 初始化烟花 void Load_Image(); // 加载烟花图片 void Shoot(); // 发射烟花 void Chose(DWORD& t1); // 筛选烟花 void Show(DWORD* pMem); // 绽放烟花 void Erase(DWORD* pMem); // 随机擦除像素点 // 烟花结构 struct FIRE { int r; // 当前爆炸半径 int max_r; // 爆炸中心距离边缘最大半径 int x, y; // 爆炸中心在窗口的坐标 int cen_x, cen_y; // 爆炸中心相对图片左上角的坐标 int width, height; // 图片的宽高 int xy[240][240]; // 储存图片像素点 bool show; // 是否绽放 bool draw; // 开始输出像素点 DWORD t1, t2, dt; // 绽放速度 }Fire[NUM]; // 烟花弹结构 struct JET { int x, y; // 喷射点坐标 int hx, hy; // 最高点坐标------将赋值给 FIRE 里面的 x, y int height; // 烟花高度 bool shoot; // 是否可以发射 DWORD t1, t2, dt; // 发射速度 IMAGE img[2]; // 储存花弹一亮一暗图片 byte n : 1; // 图片下标 }Jet[NUM]; // 初始化烟花参数 void Init_Fire() { // 分别为:烟花中心到图片边缘的最远距离、烟花中心到图片左上角的距离 (x、y) 两个分量 int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 }; int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 }; int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 }; for (int i = 0; i < NUM; i++) // 初始化烟花 { Fire[i].x = 0; // 烟花中心坐标 Fire[i].y = 0; Fire[i].width = 240; // 图片宽 Fire[i].height = 240; // 图片高 Fire[i].max_r = r[i]; // 最大半径 Fire[i].cen_x = x[i]; // 中心距左上角距离 Fire[i].cen_y = y[i]; Fire[i].show = false; // 是否绽放 Fire[i].dt = 5; // 绽放时间间隔 Fire[i].t1 = timeGetTime(); Fire[i].r = 0; // 从 0 开始绽放 Jet[i].x = -240; // 烟花弹左上角坐标 Jet[i].y = -240; Jet[i].hx = -240; // 烟花弹发射最高点坐标 Jet[i].hy = -240; Jet[i].height = 0; // 发射高度 Jet[i].t1 = timeGetTime(); Jet[i].dt = rand() % 10; // 发射速度时间间隔 Jet[i].n = 0; // 烟花弹闪烁图片下标 Jet[i].shoot = false; // 是否发射 } } // 加载图片 void Load_Image() { IMAGE fm, gm; loadimage(&fm, _T("fire/flower.jpg"), 3120, 240); for (int i = 0; i < NUM; i++) { SetWorkingImage(&fm); getimage(&gm, i * 240, 0, 240, 240); SetWorkingImage(&gm); for (int a = 0; a < 240; a++) for (int b = 0; b < 240; b++) Fire[i].xy[a][b] = getpixel(a, b); } IMAGE sm; loadimage(&sm, _T("fire/shoot.jpg"), 200, 50); for (int i = 0; i 100) { int n = rand() % 20; if (n < 13 && Jet[n].shoot == false && Fire[n].show == false) { Jet[n].x = rand() % LONG; Jet[n].y = rand() % 100 + LONG / 2; Jet[n].hx = Jet[n].x; Jet[n].hy = rand() % LONG / 3; Jet[n].height = Jet[n].y - Jet[n].hy; Jet[n].shoot = true; putimage(Jet[n].x, Jet[n].y, &Jet[n].img[Jet[n].n], SRCINVERT); } t1 = t2; } } // 扫描烟花弹并发射 void Shoot() { for (int i = 0; i Jet[i].dt&& Jet[i].shoot == true) { putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); // 烟花弹的上升 if (Jet[i].y > Jet[i].hy) { Jet[i].n++; Jet[i].y -= 5; } putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); if ((Jet[i].y - Jet[i].hy) * 4 < Jet[i].height) // 上升到高度的 3 / 4,减速 Jet[i].dt = rand() % 4 + 10; if (Jet[i].y <= Jet[i].hy) // 上升到最大高度 { putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); // 擦掉烟花弹 Fire[i].x = Jet[i].hx + 10; // 在烟花弹中间爆炸 Fire[i].y = Jet[i].hy; // 在最高点绽放 Fire[i].show = true; // 开始绽放 Jet[i].shoot = false; // 停止发射 } Jet[i].t1 = Jet[i].t2; } } } // 绽放烟花 void Show(DWORD* pMem) { // 烟花个阶段绽放时间间隔,制作变速绽放效果 int drt[16] = { 5, 5, 5, 5, 5, 6, 25, 25, 25, 25, 55, 55, 55, 55, 55 }; for (int i = 0; i Fire[i].dt&& Fire[i].show == true) { if (Fire[i].r = Fire[i].max_r - 1) { Fire[i].draw = false; Init_Fire(); } Fire[i].t1 = Fire[i].t2; } // 如果该号炮花可爆炸,根据当前爆炸半径画烟花,颜色值接近黑色的不输出。 if (Fire[i].draw) { for (double a = 0; a <= 6.28; a += 0.01) { int x1 = (int)(Fire[i].cen_x + Fire[i].r * cos(a)); // 相对于图片左上角的坐标 int y1 = (int)(Fire[i].cen_y -
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值