一聚教程网:一个值得你收藏的教程网站

热门教程

C语言实现祝福烟花操作步骤及源码

时间:2026-08-13 12:01:49 编辑:袖梨 来源:一聚教程网

C语言实现祝福烟花操作步骤及源码的重点在于把前置条件、操作顺序和容易误判的地方分清楚。

一、项目介绍

这是一个用C语言实现的祝福烟花小程序。

亦可用作表白!

编译环境:visual c++ 6.0

第三方库:Easyx2022

二、运行截图

三、主要代码

void main(){initgraph( 1200, 800 );srand( time(0) );// 播放背景音乐mciSendString( "open ./fire/bk.mp3 alias bk", 0, 0, 0 );mciSendString( "play bk repeat", 0, 0, 0 );setfillstyle( 0);setfont( 36, 0, "楷体");setcolor( LIGHTBLUE );outtextxy( 370, 100, "我爱Dotcpp!" );DWORD t1= timeGetTime();// 筛选烟花计时DWORD st1= timeGetTime();// 播放花样计时DWORD* pMem = GetImageBuffer();// 获取窗口显存指针for ( int i = 0; i < NUM; i++ )// 初始化烟花{Init( i );}Load();// 将烟花图片信息加载进相应结构中BeginBatchDraw();// 开始批量绘图while ( !kbhit() ){Sleep( 10 );// 随机选择 4000 个像素点擦除for ( int clr = 0; clr < 1000; clr++ ){for ( int j = 0; j < 2; j++ ){int px1 = rand() % 1200;int py1 = rand() % 800;if ( py1 < 799 )// 防止越界pMem[py1 * 1200 + px1] = pMem[py1 * 1200 + px1 + 1] = BLACK;// 对显存赋值擦出像素点}}Chose( t1);// 筛选烟花Shoot();// 发射烟花Show( pMem);// 绽放烟花Wishing();// 滚动字符Style( st1);// 花样发射FlushBatchDraw();// 显示前面的所有绘图操作}}

四、完整源码

祝福烟花程序下载

热门栏目