煙花的代碼c語言
❶ c語言放煙花代碼
#include "stdlib.h"
#include "graphics.h"
#include "stdio.h"
#include "math.h"
#include "conio.h "
#define PI 3.1425926
main()
{
int gdriver=DETECT,gmode,errorcode;
int a[10],b[10],x,y,c,r,i,j,t;
double rad = 0.0;
/* initialize graphics and local variables */
initgraph(&gdriver , &gmode ,"");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error : %s/n",grapherrormsg(errorcode));
printf("Please any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
randomize();
for(;!kbhit();)
{
x=rand()%500+100; /*隨機中心坐標*/
y=rand()%300+100;
for(r = 0 ;r <= 8 ; r++ ) /*煙花的大小設定*/
{
for(i = 0,rad = 0.0 ; rad < 2*PI; rad += 0.78 ) /*設定坐標*/
{
a[i++] = x + (int)r *10* cos(rad);
b[ i ] = y + (int)r *10* sin(rad);
}
t = i;
for(i=1;i<t;i++)
{
c=rand()%13+1; /*各點的顏色隨機*/
setcolor(c); /*功能:將當前圖形屏幕的當前筆畫顏色置為color.*/
circle(a[i],b[i],1);/* a[i],b[i] 為圓心 1 為半徑 畫圓 */
}
delay(10000);
delay(10000);
cleardevice();
函數名: cleardevice
功 能: 清除圖形屏幕
用 法: void far cleardevice(void);
}
}
getch();
closegraph();
函數名: closegraph
功 能: 關閉圖形系統
用 法: void far closegraph(void);
}
(1)煙花的代碼c語言擴展閱讀
C語言:表白顯示(多彩小心心)
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define I 20
#define R 340
#include <string.h>
int main()
{
char answer[10];
printf("遇到你 我才發現 曾經所有的條件 似乎都成了我等你的借口 ");
printf("我對你的感情已經決堤 所以 請允許我,從今往後映入你 明媚的眼 ");
printf("我 想和你 耳鬢廝磨,相濡以沫!");
printf("答應我吧! 輸入yes,你可以看到我的真心 ");
scanf("%s", answer);
float y, x, z, f;
for (y = 1.5f; y > -1.5f; y -= 0.1f)
{
for (x = -1.5f; x < 1.5f; x += 0.05f)
{
z = x * x + y * y - 1;
f = z * z*z - x * x*y*y*y;
putchar(f <= 0.0f ? "*********"[(int)(f*-8.0f)] : ' ');
}
putchar(' ');
}
long time;
for (;;)
{
system("color a");
for (time = 0; time<99999999; time++);
system("color b");
for (time = 0; time<99999999; time++);
system("color c");
for (time = 0; time<99999999; time++);
system("color d");
for (time = 0; time<99999999; time++);
system("color e");
for (time = 0; time<99999999; time++);
system("color f");
for (time = 0; time<99999999; time++);
system("color 0");
for (time = 0; time<99999999; time++);
system("color 1");
for (time = 0; time<99999999; time++);
system("color 2");
for (time = 0; time<99999999; time++);
system("color 3");
for (time = 0; time<99999999; time++);
system("color 4");
for (time = 0; time<99999999; time++);
system("color 5");
for (time = 0; time<99999999; time++);
system("color 6");
for (time = 0; time<99999999; time++);
system("color 7");
for (time = 0; time<99999999; time++);
system("color 8");
for (time = 0; time<99999999; time++);
system("color 9");
}
getchar();
return 0;
}
❷ c語言編程煙花代碼簡單
c語言編程煙花代碼簡單如下:
#include "stdlib.h"
#include "graphics.h"
#include "stdio.h"
#include "math.h"
#include "conio.h "
#define PI 3.1425926
main()
{
int gdriver=DETECT,gmode,errorcode;
int a[10],b[10],x,y,c,r,i,j,t;
double rad = 0.0;
/* initialize graphics and local variables */
initgraph(&gdriver , &gmode ,"");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error : %s/n",grapherrormsg(errorcode));
printf("Please any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
randomize();
for(;!kbhit();)
{
x=rand()%500+100; /*隨機中心坐標州純*/
y=rand()%300+100;
for(r = 0 ;r <= 8 ; r++ ) /*煙花的大小設定*/
{
for(i = 0,rad = 0.0 ; rad < 2*PI; rad += 0.78 ) /*設定坐標*/
{
a[i++] = x + (int)r *10* cos(rad);
b[ i ] = y + (int)r *10* sin(rad);
}
t = i;
for(i=1;i<t;i++)
{
c=rand()%13+1; /*各點的顏色隨機*/
setcolor(c); /*功能:將當前圖形屏幕的當前筆畫顏色置為color.*/
circle(a[i],b[i],1);/* a[i],b[i] 為圓心 1 為半徑 畫圓 */
}
delay(10000);
delay(10000);
cleardevice();
函數名: cleardevice
功 能: 清除圖形屏幕
用 法: void far cleardevice(void);
}
}
getch();
closegraph();
函數名: closegraph
功 能: 關閉圖形系統
用 法: void far closegraph(void);
}
初始化煙花參數
void Init( int i )
{
// 分別為:煙花余族中心到圖片邊緣的最遠距離、煙花中心到圖片左上角的距離 (x、y) 兩個分量
int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 };
int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 };
int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 };
/**** 初始化煙花 *****/
Fire[i].x = 0; // 煙花中心坐標
Fire[i].y = 0;
Fire[i].width = 240; // 圖片寬
Fire[i].height = 240; // 圖片高
Fire[i].max_r = r[i]; // 最大半徑
Fire[i].cen_x = x[i]; // 中心距左上角距離
Fire[i].cen_y = y[i];
Fire[i].show = false; // 是否綻放
Fire[i].dt = 5; // 綻放時間間隔
Fire[i].t1 = timeGetTime();
Fire[i].r = 0; // 從 0 開始綻放
/**** 初始化煙花彈 *****/
Jet[i].x = -240; // 煙花彈左上角坐標
Jet[i].y = -240;
Jet[i].hx = -240; // 煙花彈豎跡弊發射最高點坐標
Jet[i].hy = -240;
Jet[i].height = 0; // 發射高度
Jet[i].t1 = timeGetTime();
Jet[i].dt = rand() % 10; // 發射速度時間間隔
Jet[i].n = 0; // 煙花彈閃爍圖片下標
Jet[i].shoot = false; // 是否發射
}