網站首頁 編程語言 正文
頭文件 icon.h:
#pragma once #ifndef _ICON_H_ #define _ICON_H_ #include<graphics.h> #include<string.h> #include<stdlib.h> #include<iostream> #include<string> #include<Windows.h> #include<Mmsystem.h> #pragma comment(lib,"winmm.lib") using namespace std; void init() { initgraph(600, 720); setbkcolor(RGB(255, 255, 255)); cleardevice(); } void drawTree() { IMAGE tree; setfillcolor(RGB(255, 255, 255)); setbkcolor(RGB(255, 255, 255)); loadimage(&tree, "tree.jpg", 600, 580, true); putimage(0, 150, &tree); } void drawDelc() { IMAGE delc; setfillcolor(RGB(255, 255, 255)); setbkcolor(RGB(255, 255, 255)); loadimage(&delc, "delc.jpg", 150, 150, true); putimage(220, 0, &delc); } void Star(int x,int y) { IMAGE star; setfillcolor(RGB(255, 255, 255)); setbkcolor(RGB(255, 255, 255)); loadimage(&star, "star.jpg", 50, 50, true); putimage(x, y, &star); } void Shining(int x,int y) { setbkcolor(RGB(255, 255, 255)); clearrectangle(x, y, x+50, y+50); Sleep(400); Star(x, y); } void music() { mciSendString(TEXT("open Christmas.wav alias bgm"), NULL, 0, NULL); mciSendString(TEXT("play bgm"), NULL, 0, NULL); } void close() { getchar(); closegraph(); } #endif // !_ICON_H_
music函數播放同目錄下的Christmas.wav 音樂,需要自行導入音樂到同目錄下,并按情況修改該函數中音樂文件目錄,否則沒有聲音。
圖像素材也需要自行導入
cpp文件 圣誕樹.cpp:
#include<graphics.h> #include<string.h> #include<stdlib.h> #include<iostream> #include<string> #include"icon.h" using namespace std; int main() { init(); drawTree(); drawDelc(); Star(60, 360); Star(490, 360); Star(150, 180); Star(400, 180); music(); while (1) { music(); Shining(60, 360); Shining(490, 360); Shining(150, 180); Shining(400, 180); } close(); return 0; }
效果圖:
原文鏈接:https://blog.csdn.net/qq_58804632/article/details/121965224
相關推薦
- 2022-03-09 SQL數據庫語句大全_數據庫其它
- 2022-06-18 Elasticsearch之文檔批量操作示例_其它綜合
- 2023-11-20 python設置matplotlib.plot的坐標刻度和坐標范圍
- 2022-07-25 C++數據結構之雙向鏈表_C 語言
- 2022-04-27 關于AnacondaNavigator?Jupyter?Notebook更換Python內核的問題_
- 2022-12-21 Android開發ThreadPoolExecutor與自定義線程池詳解_Android
- 2023-01-03 Qt學習之容器類的使用教程詳解_C 語言
- 2022-09-29 C++?Vector迭代器失效問題的解決方法_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支