用c++语音写一个放烟花的程序
时间: 2023-03-16 15:43:39 浏览: 123
烟花程序:#include <stdio.h>
#include <math.h> // 定义烟花的类型
typedef struct {
int x;
int y;
int radius;
int color;
} Firework; // 画出烟花
void draw_firework(Firework f) {
int i, j;
// 画出外圆
for (i = -f.radius; i < f.radius; i++) {
for (j = -f.radius; j < f.radius; j++) {
if (sqrt(i * i + j * j) <= f.radius) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
} int main() {
int i;
Firework f[5];
// 初始化烟花
for (i = 0; i < 5; i++) {
f[i].x = i * 20;
f[i].y = 20;
f[i].radius = i * 3 + 5;
f[i].color = i * 10;
}
// 画出烟花
for (i = 0; i < 5; i++) {
draw_firework(f[i]);
}
return 0;
}
相关问题
用C++ege库写一个放烟花程序
好的,我可以回答这个问题。以下是一个简单的放烟花程序,使用C ege库:
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
int main()
{
initgraph(640, 480); // 初始化图形界面
srand(time(NULL)); // 设置随机数种子
while (1)
{
int x = rand() % 640; // 随机生成烟花的位置
int y = rand() % 480;
setcolor(rand() % 16 + 1); // 随机设置烟花的颜色
for (int r = 1; r <= 100; r += 5) // 循环绘制烟花的圆圈
{
circle(x, y, r);
Sleep(10);
}
cleardevice(); // 清空屏幕
}
closegraph(); // 关闭图形界面
return 0;
}
用C++写一个过年烟花程序
这是一个简单的烟花程序,使用 C 语言编写:
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
int i, j;
srand(time(NULL));
for (i = 0; i < 10; i++) {
for (j = 0; j < rand() % 20; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
这段代码会在屏幕上随机打印 10 行星星,每行星星的数量也是随机的。
如果需要给烟花增加颜色,可以使用 ANSI escape code。
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
int i, j;
srand(time(NULL));
for (i = 0; i < 10; i++) {
for (j = 0; j < rand() % 20; j++) {
printf("\033[31m*\033[0m");
}
printf("\n");
}
return 0;
}
```
这样会输出红色的星星.
还有更多关于 ANSI escape code 的用法,可以自行查询.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)