好看的c语言程序烟花源代码
烟花是人们新年、庆祝等节日最喜爱的庆祝道具之一,而用C语言编写的烟花程序更是酷炫、有趣,甚至具有一定的指导意义。
本程序采用的是Win32 API图形和多线程,实现了屏幕上多个烟花同时绽放、炫彩夺目的效果。以下是程序代码:
```
include <stdio.h>
include <windows.h>
include <stdlib.h>
include <time.h>
define MAX_FIREWORKS 10
define MAX_PARTICLES 100
struct ParticleStruct {
    float x, y;
    float vx, vy;
    float brightness;
};
源程序是指什么程序struct FireworkStruct {
    int x, y;
    int color;
    int particlesLeft;
    bool exploded;
    ParticleStruct particles[MAX_PARTICLES];
};
FireworkStruct fireworks[MAX_FIREWORKS];
int screenHeight, screenWidth;
HDC hDCMem;
HBITMAP hBitmap;
HBITMAP hOldBitmap;
void InitializeFirework(int index) {
    fireworks[index].x = rand() % screenWidth;
    fireworks[index].y = screenHeight - 1;
    fireworks[index].color = RGB(rand() % 256, rand() % 256, rand() % 256);
    fireworks[index].particlesLeft = rand() % 101 + 100;
    fireworks[index].exploded = false;
    for (int i = 0; i < MAX_PARTICLES; i++) {
        fireworks[index].particles[i].x = fireworks[index].x;
        fireworks[index].particles[i].y = fireworks[index].y;
        fireworks[index].particles[i].vx = (rand() % 11 - 5) / 10.0;
        fireworks[index].particles[i].vy = (rand() % 11 - 10) / 10.0;
        fireworks[index].particles[i].brightness = 1.0;
    }
}
void InitializeFireworks() {
    for (int i = 0; i < MAX_FIREWORKS; i++)
        InitializeFirework(i);
}
bool UpdateFirework(int index) {
    if (!fireworks[index].exploded) {
        fireworks[index].y -= rand() % 6 + 3;
        if (fireworks[index].y < screenHeight / 4) {
            fireworks[index].exploded = true;
            for (int i = 0; i < MAX_PARTICLES; i++) {
                fireworks[index].particles[i].vx = 0;
                fireworks[index].particles[i].vy = 0;
            }
        }
        return true;
    }
    else {
        bool particleExists = false;
        for (int i = 0; i < MAX_PARTICLES; i++)
        {
            fireworks[index].particles[i].vx *= 0.95;
            fireworks[index].particles[i].vy *= 0.95;
            fireworks[index].particles[i].x += fireworks[index].particles[i].vx;
            fireworks[index].particles[i].y += fireworks[index].particles[i].vy;
            fireworks[index].particles[i].brightness *= 0.975;
            if (fireworks[index].particles[i].brightness > 0.0)
                particleExists = true;
        }
        fireworks[index].particlesLeft--;
        if (fireworks[index].particlesLeft == 0 || !particleExists) {
            InitializeFirework(index);
            return false;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。