#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); }
#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); }