#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <libgg.h>
#pragma comment( lib , "libgg.lib" )
#define HNUM 50
#define TCNT 100
void hoshi( pGC gw , int sx , int sy , int V , int ang , int hsz , COLORREF c , double t );
int main( void )
{
pGC gw;
int x , y;
int i , j;
int sx[HNUM],sy[HNUM],v[HNUM],ang[HNUM],hsz[HNUM];
double t;
srand( time(NULL) );
for ( i=0 ; i<HNUM ; i++ ) {
sx[i] = 300;
sy[i] = 450;
switch ( i % 3 ) {
case 0: v[i] = 10 + rand()%3; break;
case 1: v[i] = 5 + rand()%3; break;
case 2: v[i] = 3 + rand()%3; break;
}
ang[i] = 360 / HNUM * i + rand()%5 -2;
hsz[i] = 2 + rand()%2;
}
GGSTART( gw , "花火の打ち上げ" , 800 , 600 , 0 , 0 ); gg_RsetBackColor( gw , RGB(0,0,0) ); x = 300; for ( i = 0 ; i < 450 ; i+=5 ) { int x2; x2 = x + rand()%8 - 4; y = 590 - i; gg_DrawStart( gw ); gg_clrScr( gw ); gg_drawFillCircle( gw , x2 , y , (int)(i*0.01+3) , RGB(0,200,255) ); gg_DrawEnd( gw ); Sleep( 10 ); } for ( i=0 ; i<TCNT ; i++ ) { t = 0.02 * i; gg_DrawStart( gw ); gg_clrScr( gw ); for ( j=0 ; j<HNUM ; j++ ) hoshi( gw , sx[j] , sy[j] , v[j] , ang[j] , hsz[j] , RGB(0-i*0/TCNT , 200-i*200/TCNT,255-i*255/TCNT) , t ); gg_DrawEnd( gw ); Sleep( 100 ); } gg_clrScrEW( gw ); gg_pause; return 0;
}
#define XMAG 20
#define YMAG 20
void hoshi( pGC gw , int sx , int sy , int V , int ang , int hsz , COLORREF c , double t )
{
int u , v;
double x , y;
double g = 9.8;
double vx , vy , theta;
theta = ang * 3.14159265 / 180.0;
vx = (double)V * cos( theta );
vy = (double)V * sin( theta );
y = vy*t - g*t*t/2.0; y = -y; x = vx*t; u = sx + XMAG * x; v = -sy + YMAG * y + 600; gg_drawFillCircle( gw , u , v , hsz , c );
}