马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 zhangjinxuan 于 2023-6-26 19:57 编辑
使用 windows.h 中的 beep 函数做出的洒水车 bgm:
- #include <bits/stdc++.h>
- #include <windows.h>
- using namespace std;
- const int sounds[6][8] = {
- {0, 0, 0, 0, 0, 0, 0, 0},
- {0, 130, 146, 164, 174, 195, 220, 246, },
- {0, 262, 294, 330, 349, 392, 440, 494, },
- {0, 523, 587, 659, 698, 783, 880, 987, },
- {0, 1046, 1174, 1318, 1396, 1567, 1760, 1975},
- {0, 2093, 2349, 2637, 2793, 3135, 3520, 3951},
- };
- struct Tone {
- int level, tone;
- double times = 1;
- };
- const Tone soundlist[]= {
- {0, 0, 0},
- {4, 1, 2}, {3, 6}, {3, 5}, {3, 3}, {3, 2}, {3, 3, 0.5}, {3, 2, 0.5}, {3, 1, 2}, {0, 0, 2},
- {3, 3}, {3, 5}, {4, 1}, {4, 1, 2}, {4, 1}, {4, 2}, {4, 3}, {4, 2}, {4, 1}, {3, 5, 2}, {0, 0, 2},
- {4, 1, 2}, {4, 2}, {4, 1}, {3, 6}, {3, 5}, {3, 6, 2}, {0, 0, 2},
- {3, 5}, {3, 6}, {4, 1}, {3, 3, 2}, {3, 5}, {3, 2}, {3, 3}, {3, 2}, {3, 1}, {3, 2, 2}, {0, 0, 2},
- {3, 3, 2}, {3, 5}, {3, 6, 2}, {3, 5}, {3, 6, 0.5}, {3, 5}, {3, 3}, {3, 2}, {3, 3, 0.5}, {3, 2, 0.5}, {3, 1, 2}, {0, 0, 0.5},
- {3, 3}, {3, 5}, {4, 1}, {4, 1, 2}, {4, 1}, {4, 2}, {4, 3}, {4, 2}, {4, 1}, {3, 6, 2}, {0, 0, 2},
- {4, 2}, {4, 3}, {4, 1, 2}, {3, 6}, {3, 5, 2}, {3, 6}, {3, 5, 0.5}, {3, 3, 0.5}, {0, 0, 2},
- {3, 2}, {3, 2, 2}, {3, 6}, {3, 5}, {3, 3}, {3, 2}, {3, 3, 0.5}, {3, 2, 0.5}, {3, 1}, {0, 0, 2},
- };
- const int len = sizeof(soundlist) / sizeof(Tone);
- const char* s[8] = {"-", "do", "re", "mi", "fa", "sol", "la", "si"};
- const char* l[6] = {"null", "lowest", "low", "mid", "high", "highest"};
- int main() {
- puts("-----Sprinkler-----");
- for (int i = 1; i <= len; ++i) {
- printf("\r%d %s %s ", soundlist[i].level, s[soundlist[i].tone], l[soundlist[i].tone]);
- Beep(sounds[soundlist[i].level][soundlist[i].tone], (soundlist[i].times) * 300);
- }
- printf("\rThank you for listening, Create by ZhangJinxuan^_^");
- system("pause");
- return 0;
- }
复制代码
是不是很像经常在你家门口吵的洒水车?
保证你听一遍唱一遍 |