import ; import ; import ; import ; import ; import ; import ; import ; import ; #include struct Snowflake { int x, y; // position int speed; // frames per movement int counter; // for speed timing std::string symbol; // Unicode snowflake double brightness; // simulate fade-in/out }; int main() { std::setlocale(LC_ALL, ""); // enable UTF-8 output const int width = 80; const int height = 24; const int numFlakes = 120; std::vector flakes(numFlakes); std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> xDist(0, width-1); std::uniform_int_distribution<> yDist(0, height-1); std::uniform_int_distribution<> speedDist(1,4); std::uniform_int_distribution<> symbolDist(0,3); std::uniform_real_distribution<> brightnessDist(0.3,1.0); std::uniform_int_distribution<> driftDist(-1,1); const std::vector symbols = {"*", "❄", "❅", "❆"}; for (auto &f : flakes) { f.x = xDist(gen); f.y = yDist(gen); f.speed = speedDist(gen); f.counter = 0; f.symbol = symbols[symbolDist(gen)]; f.brightness = brightnessDist(gen); } double wind = 0.0; double targetWind = 0.0; std::uniform_real_distribution<> windDist(-0.3,0.3); while (true) { // gradually change wind targetWind += windDist(gen) * 0.05; wind += (targetWind - wind) * 0.05; // clear screen #ifdef _WIN32 std::system("cls"); #else std::cout << "\x1B[2J\x1B[H"; #endif // frame buffer std::vector frame(height, std::string(width,' ')); // update flakes for (auto &f : flakes) { f.counter++; if(f.counter >= f.speed) { f.y++; f.x += static_cast(std::round(driftDist(gen) + wind)); if(f.x < 0) f.x = 0; if(f.x >= width) f.x = width-1; if(f.y >= height) { f.y = 0; f.x = xDist(gen); f.symbol = symbols[symbolDist(gen)]; f.brightness = brightnessDist(gen); f.speed = speedDist(gen); } f.counter = 0; } // simulate fade: dim flakes near top int color = static_cast(232 + f.brightness * 23); // grayscale ANSI std::cout << "\033[" << f.y+1 << ";" << f.x+1 << "H" << "\033[38;5;" << color << "m" << f.symbol; } std::cout << "\033[0m"; // reset color std::cout.flush(); std::this_thread::sleep_for(std::chrono::milliseconds(80)); } return 0; }