devc++烟花爱心代码
时间: 2023-12-25 18:30:11 浏览: 228
以下是使用DevC++编写的烟花爱心代码:
```c
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <time.h>
#define PI 3.1415926
void drawHeart(int x, int y, int size) {
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
int topCurveHeight = size / 2;
int bottomCurveHeight = size / 2;
int bottomCurveWidth = (size / 2) + (size / 4);
arc(x - size / 4, y - topCurveHeight, 0, 180, size / 4);
arc(x + size / 4, y - topCurveHeight, 0, 180, size / 4);
line(x - size / 2, y, x, y + bottomCurveHeight);
line(x + size / 2, y, x, y + bottomCurveHeight);
ellipse(x, y, 0, 360, bottomCurveWidth, bottomCurveHeight);
}
void drawFirework(int x, int y) {
int i, j;
int color;
int radius;
int angle;
int speed;
int numParticles = 100;
for (i = 0; i < numParticles; i++) {
radius = rand() % 5 + 1;
angle = rand() % 360;
speed = rand() % 5 + 1;
color = rand() % 15 + 1;
int newX = x;
int newY = y;
for (j = 0; j < 100; j++) {
newX += speed * cos(angle * PI / 180);
newY -= speed * sin(angle * PI / 180);
putpixel(newX, newY, color);
delay(10);
}
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int screenWidth = getmaxx();
int screenHeight = getmaxy();
int heartSize = 100;
int heartX = screenWidth / 2;
int heartY = screenHeight / 2 - 50;
drawHeart(heartX, heartY, heartSize);
delay(1000);
cleardevice();
int numFireworks = 10;
int i;
for (i = 0; i < numFireworks; i++) {
int fireworkX = rand() % screenWidth;
int fireworkY = rand() % screenHeight;
drawFirework(fireworkX, fireworkY);
}
getch();
closegraph();
return 0;
}
```
阅读全文