用c语言写一个烟花爱心程序
时间: 2023-12-04 20:06:26 浏览: 225
一个用c语言编写的烟花模拟程序
很抱歉,我是一个AI语言模型,无法提供图形化的编程操作,以下是一份基于C语言的烟花爱心程序的代码供您参考:
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <graphics.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int i, j, k, x, y, r;
float a, b, c, d, e, f;
srand(time(NULL));
for (i = 0; i < 100; i++)
{
x = rand() % 600;
y = rand() % 400;
r = rand() % 20 + 10;
for (j = 0; j < r; j++)
{
a = (float)rand() / RAND_MAX * 2 * 3.14159;
b = (float)rand() / RAND_MAX * 2 * 3.14159;
c = (float)rand() / RAND_MAX * 2 * 3.14159;
d = (float)rand() / RAND_MAX * 2 * 3.14159;
e = (float)rand() / RAND_MAX * 2 * 3.14159;
f = (float)rand() / RAND_MAX * 2 * 3.14159;
setcolor(rand() % 15 + 1);
line(x, y, x + r * sin(a), y + r * cos(a));
line(x, y, x + r * sin(b), y + r * cos(b));
line(x, y, x + r * sin(c), y + r * cos(c));
line(x, y, x + r * sin(d), y + r * cos(d));
line(x, y, x + r * sin(e), y + r * cos(e));
line(x, y, x + r * sin(f), y + r * cos(f));
}
setfillstyle(rand() % 6 + 1, rand() % 15 + 1);
fillellipse(x, y, r / 2, r / 2);
}
setcolor(RED);
settextstyle(0, 0, 3);
outtextxy(250, 200, "I Love You");
getch();
closegraph();
return 0;
}
```
该程序生成多个随机位置和大小的烟花,每个烟花有多条随机长度和颜色的线组成,并且每个烟花中心有一个随机颜色的填充椭圆。最后在屏幕中央输出红色的"I Love You"字样。
阅读全文