導航:首頁 > 編程知識 > 放煙花為什麼要編程

放煙花為什麼要編程

發布時間:2023-07-05 01:44:19

『壹』 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; // 是否發射

}

閱讀全文

與放煙花為什麼要編程相關的資料

熱點內容
微信零錢話費多久到賬 瀏覽:165
如何在word做柱狀圖 瀏覽:388
一生app是什麼功能 瀏覽:88
製作單文件軟體 瀏覽:692
什麼網站貸款方便 瀏覽:712
app上傳圖片php 瀏覽:887
網頁性能測試工具 瀏覽:940
文件夾怎麼壓縮發 瀏覽:166
蘋果5的文件在哪裡設置 瀏覽:173
vb更改文件名 瀏覽:879
蘋果電腦全選文件 瀏覽:330
excel數據透視表文件 瀏覽:298
榮耀5x升級後自動重啟 瀏覽:324
css文件的代碼格式 瀏覽:152
微信61安卓永不升級版 瀏覽:800
編程入門了可以做什麼 瀏覽:658
qq飛車飛碟怎麼買2017 瀏覽:727
上海哪個地方網路最好 瀏覽:983
java數據類型干什麼的 瀏覽:840
c怎麼列印文件怎麼打開 瀏覽:217

友情鏈接