-
个人简介
666 这个入是桂,当我点进他的主页后,看他通过的题目,我的鼠标都是卡的。

坏好东西博客
MC
视频
数字烟花代码(Windouws系统适用)
#include <iostream> #include <vector> #include <cmath> #include <cstdlib> #include <ctime> #include <thread> #include <chrono> #include <conio.h> #include <windows.h> struct Particle { double x, y; double vx, vy; int life; int color; char symbol; }; class Firework { private: std::vector<Particle> particles; int groundY; int width; HANDLE hConsole; CONSOLE_SCREEN_BUFFER_INFO csbi; public: Firework(int w, int h) : width(w), groundY(h) { srand(static_cast<unsigned>(time(nullptr))); hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsole, &csbi); } void launch() { int startX = rand() % (width - 40) + 20; SetConsoleTextAttribute(hConsole, 14); for(int y = groundY-1; y > groundY/4; y--) { system("cls"); drawRocket(startX, y); std::this_thread::sleep_for(std::chrono::milliseconds(25)); if(_kbhit()) { if(_getch() == 'q') return; } } explode(startX, groundY/4); } private: void drawRocket(int x, int y) { for(int i = 0; i < groundY; i++) { for(int j = 0; j < width; j++) { if(i == y && j == x) { SetConsoleTextAttribute(hConsole, 14); std::cout << "↑"; } else if(i == y-1 && j == x) { SetConsoleTextAttribute(hConsole, 12); std::cout << "●"; } else if(i == groundY - 1) { SetConsoleTextAttribute(hConsole, 8); std::cout << "▄"; } else if(i == groundY - 2 && j >= x-2 && j <= x+2) { SetConsoleTextAttribute(hConsole, 6); std::cout << "#"; } else { std::cout << " "; } } std::cout << std::endl; } SetConsoleTextAttribute(hConsole, 10); std::cout << " ?? Firework Launching... "; SetConsoleTextAttribute(hConsole, 7); } void explode(int centerX, int centerY) { const char symbols[] = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; for(int i = 0; i < 200; i++) { Particle p; p.x = centerX + (rand() % 3 - 1); p.y = centerY + (rand() % 3 - 1); double angle = (rand() % 360) * 3.14159265358979323846 / 180.0; double speed = 0.5 + (rand() % 100) * 0.015; p.vx = cos(angle) * speed; p.vy = sin(angle) * speed * 0.8; p.life = 30 + rand() % 70; p.color = rand() % 6; p.symbol = symbols[rand() % 12]; particles.push_back(p); } for(int frame = 0; frame < 100; frame++) { system("cls"); COORD trailPos = {static_cast<SHORT>(centerX), static_cast<SHORT>(centerY-1)}; SetConsoleCursorPosition(hConsole, trailPos); SetConsoleTextAttribute(hConsole, 8); std::cout << "·"; for(auto& p : particles) { if(p.life > 0) { p.x += p.vx; p.y += p.vy; p.vy += 0.06 + frame * 0.0005; p.life -= 1 + frame/30; if(p.life > 0 && p.x >= 0 && p.x < width && p.y >= 0 && p.y < groundY) { COORD pos = {static_cast<SHORT>(p.x), static_cast<SHORT>(p.y)}; SetConsoleCursorPosition(hConsole, pos); int colors[] = {12, 14, 13, 11, 10, 15}; int fadeColors[] = {8, 7, 0}; int colorIdx; if(p.life > 40) colorIdx = colors[p.color]; else if(p.life > 15) colorIdx = 7; else colorIdx = fadeColors[p.life/5]; SetConsoleTextAttribute(hConsole, colorIdx); if(p.life < 10 && rand() % 3 == 0) std::cout << " "; else std::cout << p.symbol; } } } for(int i = 0; i < groundY; i++) { COORD pos = {0, static_cast<SHORT>(groundY)}; SetConsoleCursorPosition(hConsole, pos); SetConsoleTextAttribute(hConsole, 8); for(int j = 0; j < width; j++) std::cout << "▄"; } std::cout.flush(); std::this_thread::sleep_for(std::chrono::milliseconds(35)); if(_kbhit()) { char ch = _getch(); if(ch == 'q' || ch == 'Q') break; if(ch == 27) break; } } particles.clear(); system("cls"); SetConsoleTextAttribute(hConsole, 14); COORD msgPos = {static_cast<SHORT>(width/2 - 5), static_cast<SHORT>(groundY/2)}; SetConsoleCursorPosition(hConsole, msgPos); std::cout << "? BOOM! ?"; std::this_thread::sleep_for(std::chrono::milliseconds(500)); SetConsoleTextAttribute(hConsole, 7); } }; void setConsoleSize(int width, int height) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SMALL_RECT rect = {0, 0, static_cast<SHORT>(width-1), static_cast<SHORT>(height-1)}; COORD coord = {static_cast<SHORT>(width), static_cast<SHORT>(height)}; SetConsoleScreenBufferSize(hConsole, coord); SetConsoleWindowInfo(hConsole, TRUE, &rect); } void showTitle() { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); system("cls"); SetConsoleTextAttribute(hConsole, 13); std::cout << "\n\n"; std::cout << " ╔══════════════════════════════════╗\n"; std::cout << " ║ ?? FIREWORKS DISPLAY ?? ║\n"; std::cout << " ╚══════════════════════════════════╝\n\n"; SetConsoleTextAttribute(hConsole, 11); std::cout << " Controls:\n"; std::cout << " ? Press ENTER to launch firework\n"; std::cout << " ? Press Q or ESC to quit\n"; std::cout << " ? During animation press any key to skip\n\n"; SetConsoleTextAttribute(hConsole, 10); std::cout << " Press ENTER to begin the show...\n"; SetConsoleTextAttribute(hConsole, 7); std::cin.ignore(); } int main() { system("mode con: cols=80 lines=30"); setConsoleSize(80, 30); showTitle(); HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(hConsole, &csbi); int width = csbi.srWindow.Right - csbi.srWindow.Left + 1; int height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; Firework fw(width, height - 3); char cmd = ' '; int fireworkCount = 0; while(cmd != 'q' && cmd != 'Q') { system("cls"); SetConsoleTextAttribute(hConsole, 14); COORD countPos = {0, 0}; SetConsoleCursorPosition(hConsole, countPos); std::cout << "?? Fireworks launched: " << fireworkCount << " "; SetConsoleTextAttribute(hConsole, 7); COORD promptPos = {0, static_cast<SHORT>(height - 2)}; SetConsoleCursorPosition(hConsole, promptPos); std::cout << "Press ENTER to launch (Q to quit): "; if(_kbhit()) { cmd = _getch(); if(cmd == 'q' || cmd == 'Q' || cmd == 27) break; } std::cin.ignore(); fw.launch(); fireworkCount++; if(fireworkCount % 5 == 0) { system("cls"); SetConsoleTextAttribute(hConsole, 13); COORD specialPos = {static_cast<SHORT>(width/2-10), static_cast<SHORT>(height/2)}; SetConsoleCursorPosition(hConsole, specialPos); std::cout << "?? SPECIAL COMBO! ??"; std::this_thread::sleep_for(std::chrono::milliseconds(800)); } } system("cls"); SetConsoleTextAttribute(hConsole, 14); COORD endPos = {static_cast<SHORT>(width/2-15), static_cast<SHORT>(height/2-1)}; SetConsoleCursorPosition(hConsole, endPos); std::cout << "══════════════════════════════════════\n"; SetConsoleCursorPosition(hConsole, {static_cast<SHORT>(endPos.X), static_cast<SHORT>(endPos.Y+1)}); std::cout << " ?? THANKS FOR WATCHING! ?? \n"; SetConsoleCursorPosition(hConsole, {static_cast<SHORT>(endPos.X), static_cast<SHORT>(endPos.Y+2)}); std::cout << " Total fireworks: " << fireworkCount << " \n"; SetConsoleCursorPosition(hConsole, {static_cast<SHORT>(endPos.X), static_cast<SHORT>(endPos.Y+3)}); std::cout << "══════════════════════════════════════\n"; SetConsoleTextAttribute(hConsole, 7); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); return 0; }macOS适用代码
#include <iostream> #include <vector> #include <cmath> #include <cstdlib> #include <ctime> #include <thread> #include <chrono> #include <termios.h> #include <unistd.h> #include <sys/ioctl.h> struct Particle{ double x,y; double vx,vy; int life; char symbol; }; class Firework{ private: std::vector<Particle>particles; int groundY; int width; public: Firework(int w,int h):width(w),groundY(h){ srand(time(nullptr)); } void launch(){ int startX=rand()%(width-20)+10; for(int y=groundY-1;y>groundY/3;y--){ printf("\033[2J"); drawRocket(startX,y); std::this_thread::sleep_for(std::chrono::milliseconds(30)); } explode(startX,groundY/3); } private: void drawRocket(int x,int y){ for(int i=0;i<groundY;i++){ for(int j=0;j<width;j++){ if(i==y&&j==x)printf("\033[93m|\033[0m"); else if(i==groundY-1)printf("\033[37m_\033[0m"); else printf(" "); } printf("\n"); } printf("\033[92m火箭上升中...\033[0m\n"); } void explode(int centerX,int centerY){ for(int i=0;i<150;i++){ Particle p; p.x=centerX; p.y=centerY; double angle=(rand()%360)*3.14159/180.0; double speed=0.3+(rand()%70)*0.01; p.vx=cos(angle)*speed; p.vy=sin(angle)*speed; p.life=25+rand()%50; char symbols[]=".*o@$#&%"; p.symbol=symbols[rand()%8]; particles.push_back(p); } for(int frame=0;frame<70;frame++){ printf("\033[2J"); for(auto&p:particles){ if(p.life>0){ p.x+=p.vx; p.y+=p.vy; p.vy+=0.05; p.life--; if(p.life>0){ int px=static_cast<int>(p.x); int py=static_cast<int>(p.y); if(px>=0&&px<width&&py>=0&&py<groundY){ printf("\033[%d;%dH",py+1,px+1); if(p.life>20)printf("\033[91m"); else if(p.life>10)printf("\033[93m"); else printf("\033[90m"); putchar(p.symbol); } } } } printf("\033[%d;1H\033[0m",groundY+1); fflush(stdout); std::this_thread::sleep_for(std::chrono::milliseconds(50)); } particles.clear(); } }; int main(){ struct winsize w; ioctl(STDOUT_FILENO,TIOCGWINSZ,&w); printf("\033[2J\033[?25l"); Firework fw(w.ws_col,w.ws_row-2); printf("\033[%d;1H?? 按回车发射烟花,输入q退出 ??\n",w.ws_row); char cmd=' '; while(cmd!='q'){ fw.launch(); printf("\033[%d;1H再放一个?(回车继续/q退出):",w.ws_row); fflush(stdout); std::cin.get(cmd); if(cmd!='\n')std::cin.ignore(1000,'\n'); } printf("\033[2J\033[%d;1H\033[37m感谢观看!\033[0m\033[?25h\n",w.ws_row/2); return 0; }(AI生成)

-
最近活动
- 武义双语 金华市素养大赛 赛前辅导 (二维矩阵和字符串、数学专题) 2025.12.01 OI
- 分支嵌套 ACM/ICPC
- 金华市青少年信息学素养大赛 2024 OI
- 上海零基础 if语句 IOI
- 2025年 国庆假期 竞赛集训 考前模拟 10.07 OI
- 2025年 武义双语 信息素养 考前模拟 12.04 OI
- 2025年 武义双语 信息素养 考前模拟 12.03 OI
- 2025年 武义双语 素养大赛 考前模拟 12.02 OI
- 2025年 武义学校 竞赛集训 基础算法 08.30 OI
- 2025年 武义学校 竞赛集训 赛前训练:文件读写 8.30 OI
- 2025年 武义学校 竞赛集训 结业考试 08.30 OI
- 2025年 武义学校 竞赛集训 进制转换 挑战题 08.29 OI
- 2025年 武义学校 竞赛集训 字符串 挑战题 08.29 OI
- 2025年 武义学校 竞赛集训 字符串 挑战题 08.28 OI
- 2025年 武义学校 竞赛集训 排序算法 挑战题 08.28 OI
- 2025年 武义学校 竞赛集训 二分查找 挑战题 08.27 OI
- 2025年 武义学校 竞赛集训 数组和向量 挑战题 08.27 OI
- 2025年 武义学校 竞赛集训 特别 挑战题 08.25 OI
- 2025年 武义学校 竞赛集训 多重循环 与 暴力枚举 挑战题 08.25 OI
- 2025年 武义学校 竞赛集训 质因数分解 挑战题 08.25 OI
- 2025年 武义学校 竞赛集训 数学专题 挑战题 08.24 OI
- 2025年 武义学校 竞赛集训 编程要素 分支结构 循环结构 挑战题 08.24 OI
- 2025年 国庆假期 竞赛集训 语法基础测试 10.01 IOI