祝大家2026快乐!
2026-02-15 16:54:44
发布于:湖南
这不2026了吗,所以我准备放个烟花,但是莫得,气死我了
我是那么容易轻易放弃的人吗?
法律不让在现实干,那我就在电脑里干!
C++(独属于windows的)烟花代码:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <vector>
#include <array>
#include <random>
#include <cmath>
#include <algorithm>
#include <chrono>
using namespace std;
const int DISPLAY_WIDTH = 800;
const int DISPLAY_HEIGHT = 800;
const COLORREF BG_COLOR = RGB(20, 20, 30);
class Vector2 {
public:
float x, y;
Vector2() : x(0.0f), y(0.0f) {}
Vector2(float x_, float y_) : x(x_), y(y_) {}
Vector2& operator+=(const Vector2& other) {
x += other.x;
y += other.y;
return *this;
}
Vector2& operator-=(const Vector2& other) {
x -= other.x;
y -= other.y;
return *this;
}
Vector2& operator*=(float scalar) {
x *= scalar;
y *= scalar;
return *this;
}
Vector2& operator/=(float scalar) {
x /= scalar;
y /= scalar;
return *this;
}
Vector2 operator+(const Vector2& other) const {
return Vector2(x + other.x, y + other.y);
}
Vector2 operator-(const Vector2& other) const {
return Vector2(x - other.x, y - other.y);
}
Vector2 operator*(float scalar) const {
return Vector2(x * scalar, y * scalar);
}
Vector2 operator/(float scalar) const {
return Vector2(x / scalar, y / scalar);
}
float length() const {
return std::sqrt(x * x + y * y);
}
float length_squared() const {
return x * x + y * y;
}
Vector2 normalized() const {
float len = length();
return len > 0 ? Vector2(x / len, y / len) : Vector2();
}
float distance_to(const Vector2& other) const {
float dx = x - other.x;
float dy = y - other.y;
return std::sqrt(dx * dx + dy * dy);
}
};
const Vector2 gravity(0.0f, 0.12f);
const float air_drag = 0.001f;
const float wind_turbulence = 0.015f;
const int dynamic_offset = 1;
const int static_offset = 5;
enum FireworkType {
TYPE_SPHERE,
TYPE_HEART,
TYPE_STAR,
TYPE_LINE,
TYPE_SPARKLE,
TYPE_2026,
TYPE_CIRCLE_RING,
TYPE_FLOWER,
TYPE_SPIRAL,
TYPE_DOUBLE_HEART,
TYPE_NULL,
TYPE_RANDOM_BURST
};
std::random_device rd;
std::mt19937 gen(rd());
int randint(int min, int max) {
std::uniform_int_distribution<> dist(min, max);
return dist(gen);
}
float uniform(float min, float max) {
std::uniform_real_distribution<> dist(min, max);
return static_cast<float>(dist(gen));
}
template <typename T>
T choice(const std::vector<T>& vec) {
if (vec.empty()) return T();
return vec[randint(0, static_cast<int>(vec.size()) - 1)];
}
class Trail {
public:
int pos_in_line;
Vector2 pos;
Vector2 prev_pos;
bool dynamic;
int size;
float life_ratio;
Trail(int n, int size_, bool dynamic_)
: pos_in_line(n), pos(-10.0f, -10.0f), prev_pos(-10.0f, -10.0f),
dynamic(dynamic_), size(size_), life_ratio(1.0f) {
if (dynamic) {
size = std::max(size_ - n / 2, 1);
} else {
size = std::max(size_ - 2, 1);
}
}
void get_pos(int x, int y) {
prev_pos = pos;
pos = Vector2(static_cast<float>(x), static_cast<float>(y));
}
void show(HDC hdc, COLORREF base_colour, float parent_life_ratio) {
life_ratio = 1.0f - static_cast<float>(pos_in_line) / 5.0f;
float total_alpha = life_ratio * parent_life_ratio;
int r = static_cast<int>(GetRValue(base_colour) * total_alpha + GetRValue(BG_COLOR) * (1 - total_alpha));
int g = static_cast<int>(GetGValue(base_colour) * total_alpha + GetGValue(BG_COLOR) * (1 - total_alpha));
int b = static_cast<int>(GetBValue(base_colour) * total_alpha + GetBValue(BG_COLOR) * (1 - total_alpha));
COLORREF col = RGB(r, g, b);
if (prev_pos.x != -10 && pos.x != -10) {
HPEN hPen = CreatePen(PS_SOLID, size, col);
HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);
MoveToEx(hdc, static_cast<int>(prev_pos.x), static_cast<int>(prev_pos.y), NULL);
LineTo(hdc, static_cast<int>(pos.x), static_cast<int>(pos.y));
SelectObject(hdc, hOldPen);
DeleteObject(hPen);
}
}
};
class Particle {
public:
bool firework;
Vector2 pos;
Vector2 origin;
bool remove;
int explosion_radius;
int life;
int max_life;
Vector2 acc;
std::vector<Trail> trails;
std::array<int, 10> prev_posx;
std::array<int, 10> prev_posy;
Vector2 vel;
int size;
COLORREF colour;
COLORREF original_colour;
bool is_sparkle;
int sparkle_timer;
bool can_explode;
int secondary_explosion_time;
std::vector<COLORREF> secondary_colours;
Particle(float x, float y, bool firework_, const std::vector<COLORREF>& colour_list, bool sparkle_ = false)
: firework(firework_), pos(x, y), origin(x, y), remove(false),
explosion_radius(randint(10, 25)), life(0), max_life(120), acc(0.0f, 0.0f),
prev_posx({-10, -10, -10, -10, -10, -10, -10, -10, -10, -10}),
prev_posy({-10, -10, -10, -10, -10, -10, -10, -10, -10, -10}),
is_sparkle(sparkle_), sparkle_timer(0),
can_explode(false), secondary_explosion_time(0) {
int trail_size = firework ? 4 : randint(2, 3);
for (int i = 0; i < 5; i++) trails.emplace_back(i, trail_size, firework);
if (firework) {
vel = Vector2(uniform(-0.5f, 0.5f), static_cast<float>(-randint(16, 19)));
size = 4;
original_colour = colour_list[0];
} else {
vel = Vector2(uniform(-1.0f, 1.0f), uniform(-1.0f, 1.0f)).normalized() * static_cast<float>(randint(8, explosion_radius + 8));
size = randint(2, 4);
original_colour = choice(colour_list);
max_life = explosion_radius >= 150 ? 180 : 100;
}
colour = original_colour;
}
Particle(float x, float y, bool firework_, COLORREF colour_, bool sparkle_ = false, Vector2 initial_vel = Vector2(0, 0))
: firework(firework_), pos(x, y), origin(x, y), remove(false),
explosion_radius(randint(10, 25)), life(0), max_life(120), acc(0.0f, 0.0f),
prev_posx({-10, -10, -10, -10, -10, -10, -10, -10, -10, -10}),
prev_posy({-10, -10, -10, -10, -10, -10, -10, -10, -10, -10}),
is_sparkle(sparkle_), sparkle_timer(0),
can_explode(false), secondary_explosion_time(0) {
int trail_size = firework ? 4 : randint(2, 3);
for (int i = 0; i < 5; i++) trails.emplace_back(i, trail_size, firework);
if (firework) {
vel = (initial_vel.x != 0 || initial_vel.y != 0) ? initial_vel : Vector2(uniform(-0.5f, 0.5f), static_cast<float>(-randint(16, 19)));
size = 4;
original_colour = colour_;
} else {
vel = Vector2(uniform(-1.0f, 1.0f), uniform(-1.0f, 1.0f)).normalized() * static_cast<float>(randint(8, explosion_radius + 8));
size = randint(2, 4);
original_colour = colour_;
max_life = 100;
}
colour = original_colour;
}
void apply_force(const Vector2& force) {
acc += force;
}
void move() {
if (vel.length_squared() > 0) {
Vector2 drag = vel.normalized() * (-air_drag * vel.length_squared());
apply_force(drag);
}
apply_force(Vector2(uniform(-wind_turbulence, wind_turbulence), 0));
vel += acc;
vel *= 0.92f;
pos += vel;
acc = Vector2(0, 0);
if (life == 0 && !firework) {
if (pos.distance_to(origin) > explosion_radius) remove = true;
}
decay();
trail_update();
life++;
float ratio = 1.0f - (static_cast<float>(life) / max_life);
ratio = max(0.0f, min(1.0f, ratio));
int r = static_cast<int>(GetRValue(original_colour) * ratio + GetRValue(BG_COLOR) * (1 - ratio));
int g = static_cast<int>(GetGValue(original_colour) * ratio + GetGValue(BG_COLOR) * (1 - ratio));
int b = static_cast<int>(GetBValue(original_colour) * ratio + GetBValue(BG_COLOR) * (1 - ratio));
colour = RGB(r, g, b);
}
void show(HDC hdc) {
float life_ratio = 1.0f - (static_cast<float>(life) / max_life);
for (auto& t : trails) t.show(hdc, original_colour, life_ratio);
if (size > 0 && life_ratio > 0.1f) {
int glow_size = size + 2;
COLORREF glow_col = RGB((GetRValue(colour) + GetRValue(BG_COLOR)) / 2, (GetGValue(colour) + GetGValue(BG_COLOR)) / 2, (GetBValue(colour) + GetBValue(BG_COLOR)) / 2);
SetDCBrushColor(hdc, glow_col);
SelectObject(hdc, GetStockObject(DC_BRUSH));
Ellipse(hdc, (int)pos.x - glow_size, (int)pos.y - glow_size, (int)pos.x + glow_size, (int)pos.y + glow_size);
SetDCBrushColor(hdc, colour);
SelectObject(hdc, GetStockObject(DC_BRUSH));
Ellipse(hdc, (int)pos.x - size, (int)pos.y - size, (int)pos.x + size, (int)pos.y + size);
}
}
void decay() {
if (life > max_life * 0.6f) {
if (randint(0, 4) == 0) remove = true;
}
}
void trail_update() {
for (int i = 9; i > 0; i--) {
prev_posx[i] = prev_posx[i - 1];
prev_posy[i] = prev_posy[i - 1];
}
prev_posx[0] = (int)pos.x;
prev_posy[0] = (int)pos.y;
for (size_t n = 0; n < trails.size(); n++) {
int idx = trails[n].dynamic ? (n + dynamic_offset) : (n + static_offset);
if (idx < 10) trails[n].get_pos(prev_posx[idx], prev_posy[idx]);
}
}
};
class Firework {
public:
COLORREF colour;
std::vector<COLORREF> colours;
Particle firework;
bool exploded;
std::vector<Particle> particles;
std::vector<Particle> secondary_particles;
Vector2 min_max_particles;
FireworkType type;
bool full_secondary_explosion;
Firework(float x, float y)
: firework(x, y, true, RGB(255, 255, 255), false, Vector2(uniform(-1.0f, 1.0f), static_cast<float>(-randint(70, 80)))),
exploded(false), min_max_particles(200, 300), full_secondary_explosion(randint(0, 4) == 0) {
std::vector<COLORREF> palette = {
RGB(255, 60, 60),
RGB(255, 180, 80),
RGB(255, 255, 120),
RGB(120, 255, 120),
RGB(100, 150, 255),
RGB(200, 120, 255),
RGB(255, 255, 255)
};
int type_rand = randint(0, 99);
if (type_rand < 50) type = TYPE_SPHERE;
else if (type_rand < 65) type = TYPE_NULL;
else type = static_cast<FireworkType>(randint(1, 11));
colour = choice(palette);
for (int i = 0; i < 3; i++) colours.push_back(choice(palette));
firework.original_colour = colour;
firework.colour = colour;
switch (type) {
case TYPE_STAR:
min_max_particles = Vector2(150, 250);
break;
case TYPE_HEART:
min_max_particles = Vector2(250, 350);
break;
case TYPE_2026:
min_max_particles = Vector2(500, 600);
break;
case TYPE_NULL:
min_max_particles = Vector2(0, 0);
break;
case TYPE_LINE:
min_max_particles = Vector2(100, 200);
break;
case TYPE_SPARKLE:
min_max_particles = Vector2(300, 400);
break;
case TYPE_CIRCLE_RING:
min_max_particles = Vector2(150, 250);
break;
case TYPE_FLOWER:
min_max_particles = Vector2(200, 300);
break;
case TYPE_SPIRAL:
min_max_particles = Vector2(250, 350);
break;
case TYPE_DOUBLE_HEART:
min_max_particles = Vector2(300, 400);
break;
case TYPE_RANDOM_BURST:
min_max_particles = Vector2(200, 400);
break;
default:
break;
}
}
void update(HDC hdc) {
if (!exploded) {
firework.apply_force(gravity);
firework.move();
firework.show(hdc);
if (firework.vel.y >= 0) {
exploded = true;
explode();
}
} else {
for (auto& p : particles) {
Vector2 f(gravity.x, gravity.y * 0.6f);
p.apply_force(f);
p.move();
if (p.can_explode && p.life >= p.secondary_explosion_time) {
trigger_secondary(p);
p.remove = true;
}
p.show(hdc);
}
for (auto& sp : secondary_particles) {
sp.apply_force(Vector2(0, gravity.y * 0.5f));
sp.move();
sp.show(hdc);
}
}
}
void trigger_secondary(const Particle& parent) {
int cnt = full_secondary_explosion ? 10 : 25;
for (int i = 0; i < cnt; i++) {
Particle p(parent.pos.x, parent.pos.y, false, parent.secondary_colours);
p.vel = Vector2(uniform(-1, 1), uniform(-1, 1)).normalized() * static_cast<float>(randint(3, 8));
p.size = randint(1, 2);
p.max_life = 60;
secondary_particles.push_back(p);
}
}
void explode_2026(float ox, float oy, const std::vector<COLORREF>& cols, int fix_time) {
const int R = 8, C = 8, S = 6;
unsigned char n2[R][C] = {{0, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1}
};
unsigned char n0[R][C] = {{0, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 0, 0, 0, 0, 1, 1}, {1, 1, 0, 0, 0, 0, 1, 1}, {1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1}, {1, 1, 0, 0, 0, 0, 1, 1}, {1, 1, 0, 0, 0, 0, 1, 1}, {0, 1, 1, 1, 1, 1, 1, 0}
};
unsigned char n6[R][C] = {{0, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 0, 0, 0, 0, 1, 1}, {1, 1, 0, 0, 0, 0, 1, 1}, {1, 1, 0, 0, 0, 0, 1, 1}, {0, 1, 1, 1, 1, 1, 1, 0}
};
unsigned char* seq[4] = {&n2[0][0], &n0[0][0], &n2[0][0], &n6[0][0]};
for (int n = 0; n < 4; n++) {
int off_x = n * (C + 2);
for (int r = 0; r < R; r++) {
for (int c = 0; c < C; c++) {
if (seq[n][r * C + c]) {
float x = (off_x + c - 19) * S + uniform(-1, 1);
float y = (r - 4) * S + uniform(-1, 1);
Particle p(ox, oy, false, cols);
p.vel = Vector2(x * 0.18f, y * 0.18f);
p.explosion_radius = 60;
p.max_life = 200;
if (full_secondary_explosion) {
p.can_explode = true;
p.secondary_explosion_time = fix_time;
p.secondary_colours = cols;
}
particles.push_back(p);
}
}
}
}
}
void explode() {
int amt = randint((int)min_max_particles.x, (int)min_max_particles.y);
float ox = firework.pos.x, oy = firework.pos.y;
std::vector<COLORREF> gold = {RGB(255, 215, 0), RGB(255, 255, 200), RGB(255, 140, 0)};
int fix_t = randint(20, 28);
switch (type) {
case TYPE_2026: {
explode_2026(ox, oy, gold, fix_t);
break;
}
case TYPE_SPHERE:
for (int i = 0; i < amt; i++) {
float a = uniform(0, 6.28f);
Particle p(ox, oy, false, colours);
p.vel = Vector2(cos(a), sin(a)) * uniform(8, 16);
if (full_secondary_explosion) {
p.can_explode = true;
p.secondary_explosion_time = fix_t;
p.secondary_colours = gold;
}
particles.push_back(p);
}
break;
case TYPE_HEART:
for (int i = 0; i < amt; i++) {
float t = uniform(0, 6.28f);
float x = 16 * pow(sin(t), 3);
float y = -(13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t));
float s = uniform(3, 6);
Particle p(ox, oy, false, colours);
p.vel = Vector2(x * s * 0.15f, y * s * 0.15f);
p.explosion_radius = 80;
particles.push_back(p);
}
break;
case TYPE_STAR: {
const int POINTS = 5;
for (int i = 0; i < amt; i++) {
float angle = uniform(0, 6.28f);
int point_idx = static_cast<int>(angle / (6.28f / POINTS));
float star_angle = point_idx * (6.28f / POINTS);
float inner_radius = uniform(4, 8);
float outer_radius = uniform(12, 20);
float radius = (fmod(angle - star_angle, 6.28f / POINTS) < 6.28f / (2 * POINTS)) ? outer_radius : inner_radius;
Particle p(ox, oy, false, colours);
p.vel = Vector2(cos(angle), sin(angle)) * radius;
p.explosion_radius = 100;
if (full_secondary_explosion) {
p.can_explode = true;
p.secondary_explosion_time = fix_t;
p.secondary_colours = gold;
}
particles.push_back(p);
}
break;
}
case TYPE_LINE: {
int line_type = randint(0, 3);
float angle = 0;
switch (line_type) {
case 0:
angle = 0;
break;
case 1:
angle = 1.57f;
break;
case 2:
angle = 0.785f;
break;
case 3:
angle = 2.356f;
break;
}
for (int i = 0; i < amt; i++) {
float offset = uniform(-20, 20);
float perp_angle = angle + 1.57f;
Vector2 dir(cos(angle), sin(angle));
Vector2 perp_dir(cos(perp_angle), sin(perp_angle));
Particle p(ox, oy, false, colours);
p.vel = dir * uniform(10, 18) + perp_dir * offset * 0.3f;
p.explosion_radius = 120;
particles.push_back(p);
}
break;
}
case TYPE_SPARKLE: {
for (int i = 0; i < amt; i++) {
Particle p(ox, oy, false, colours, true);
float speed = uniform(5, 20);
float a = uniform(0, 6.28f);
p.vel = Vector2(cos(a), sin(a)) * speed;
p.max_life = randint(60, 100);
p.size = randint(1, 2);
if (randint(0, 3) == 0) {
p.can_explode = true;
p.secondary_explosion_time = randint(10, 30);
p.secondary_colours = colours;
}
particles.push_back(p);
}
break;
}
case TYPE_CIRCLE_RING: {
float ring_radius = uniform(15, 25);
for (int i = 0; i < amt; i++) {
float a = uniform(0, 6.28f);
Particle p(ox, oy, false, colours);
float offset = uniform(-2, 2);
p.vel = Vector2(cos(a), sin(a)) * (ring_radius + offset);
p.explosion_radius = 150;
if (full_secondary_explosion) {
p.can_explode = true;
p.secondary_explosion_time = fix_t;
p.secondary_colours = gold;
}
particles.push_back(p);
}
break;
}
case TYPE_FLOWER: {
const int PETALS = randint(6, 12);
const int LAYERS = 3;
for (int layer = 0; layer < LAYERS; layer++) {
float layer_radius = 8 + layer * 6;
for (int i = 0; i < amt / LAYERS; i++) {
int petal_idx = randint(0, PETALS - 1);
float base_angle = petal_idx * (6.28f / PETALS);
float angle = base_angle + uniform(-0.2f, 0.2f);
Particle p(ox, oy, false, colours);
p.vel = Vector2(cos(angle), sin(angle)) * uniform(layer_radius, layer_radius + 4);
p.explosion_radius = 100;
particles.push_back(p);
}
}
break;
}
case TYPE_SPIRAL: {
float turns = uniform(1, 3);
for (int i = 0; i < amt; i++) {
float t = uniform(0, turns * 6.28f);
float radius = t * 2;
float angle = t;
Particle p(ox, oy, false, colours);
p.vel = Vector2(cos(angle), sin(angle)) * uniform(radius * 0.5f, radius);
p.explosion_radius = 150;
p.max_life = 150;
particles.push_back(p);
}
break;
}
case TYPE_DOUBLE_HEART: {
for (int i = 0; i < amt / 2; i++) {
float t = uniform(0, 6.28f);
float x = 16 * pow(sin(t), 3);
float y = -(13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t));
float s = uniform(2, 5);
Particle p(ox - 20, oy, false, colours);
p.vel = Vector2(x * s * 0.12f, y * s * 0.12f);
p.explosion_radius = 80;
particles.push_back(p);
}
for (int i = 0; i < amt / 2; i++) {
float t = uniform(0, 6.28f);
float x = 16 * pow(sin(t), 3);
float y = -(13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t));
float s = uniform(2, 5);
Particle p(ox + 20, oy, false, colours);
p.vel = Vector2(x * s * 0.12f, y * s * 0.12f);
p.explosion_radius = 80;
particles.push_back(p);
}
break;
}
case TYPE_RANDOM_BURST: {
for (int i = 0; i < amt; i++) {
Particle p(ox, oy, false, colours);
float speed = uniform(5, 25);
float a = uniform(0, 6.28f);
p.vel = Vector2(cos(a), sin(a)) * speed;
p.max_life = randint(80, 150);
p.size = randint(1, 4);
p.explosion_radius = randint(50, 150);
if (randint(0, 5) == 0) {
p.can_explode = true;
p.secondary_explosion_time = randint(15, 40);
p.secondary_colours = colours;
}
particles.push_back(p);
}
break;
}
case TYPE_NULL: {
break;
}
}
}
bool remove() {
particles.erase(remove_if(particles.begin(), particles.end(), [](auto & p) {
return p.remove;
}), particles.end());
secondary_particles.erase(remove_if(secondary_particles.begin(), secondary_particles.end(), [](auto & p) {
return p.remove;
}), secondary_particles.end());
return exploded && particles.empty() && secondary_particles.empty();
}
};
HWND g_hWnd = nullptr;
HDC g_hMemDC = nullptr;
HBITMAP g_hMemBmp = nullptr;
std::vector<Firework> g_fireworks;
bool g_running = true;
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE: {
HDC hdc = GetDC(hWnd);
g_hMemDC = CreateCompatibleDC(hdc);
g_hMemBmp = CreateCompatibleBitmap(hdc, DISPLAY_WIDTH, DISPLAY_HEIGHT);
SelectObject(g_hMemDC, g_hMemBmp);
ReleaseDC(hWnd, hdc);
return 0;
}
case WM_LBUTTONDOWN: {
int x = LOWORD(lParam);
g_fireworks.emplace_back((float)x, 800);
return 0;
}
case WM_RBUTTONDOWN: {
int x = LOWORD(lParam);
Firework fw((float)x, 800);
fw.type = TYPE_2026;
fw.colours = {RGB(255, 50, 50), RGB(255, 215, 0), RGB(255, 255, 200)};
g_fireworks.push_back(fw);
return 0;
}
case WM_KEYDOWN:
if (wParam == VK_ESCAPE) {
g_running = false;
DestroyWindow(hWnd);
}
return 0;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
SetDCBrushColor(g_hMemDC, BG_COLOR);
SelectObject(g_hMemDC, GetStockObject(DC_BRUSH));
Rectangle(g_hMemDC, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
for (auto& fw : g_fireworks) fw.update(g_hMemDC);
BitBlt(hdc, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, g_hMemDC, 0, 0, SRCCOPY);
EndPaint(hWnd, &ps);
return 0;
}
case WM_CLOSE:
g_running = false;
DestroyWindow(hWnd);
return 0;
case WM_DESTROY:
DeleteObject(g_hMemBmp);
DeleteDC(g_hMemDC);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
ShowWindow(GetConsoleWindow(), SW_HIDE);
WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInstance, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), NULL, "FireworkReal", LoadIcon(NULL, IDI_APPLICATION)};
RegisterClassEx(&wc);
g_hWnd = CreateWindowEx(0, "真实烟花", "真实烟花模拟(点击发射(右键有惊喜))", WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME, CW_USEDEFAULT, CW_USEDEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, NULL, NULL, hInstance, NULL);
ShowWindow(g_hWnd, nCmdShow);
UpdateWindow(g_hWnd);
MSG msg;
while (g_running) {
DWORD start = GetTickCount();
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT) g_running = false;
}
g_fireworks.erase(remove_if(g_fireworks.begin(), g_fireworks.end(), [](auto & fw) {
return fw.remove();
}), g_fireworks.end());
InvalidateRect(g_hWnd, NULL, FALSE);
UpdateWindow(g_hWnd);
if (16 > GetTickCount() - start) Sleep(16 - (GetTickCount() - start));
}
UnregisterClass("FireworkReal", hInstance);
return 0;
}
运行效果:

最后祝大家
一帆风顺,二龙腾飞,三阳开泰,四季平安,五福临门。
六六大顺,七星高照,八方来财,九九同心,十全十美。
(点个赞呗thank you)
新年快乐!
全部评论 4
在哪里运行?
4天前 来自 江西
1Dev C++
4天前 来自 浙江
1对
3天前 来自 湖南
1
新年快乐!
4天前 来自 江西
1乡下是让放烟花的
3天前 来自 江苏
0
4天前 来自 上海
0






































有帮助,赞一个