/*
 EGGX を使ったサンプル
 雪が降る

 473088 榎田裕一郎
*/

#include <eggx.h>
#include <math.h>
#include <stdlib.h>

int snowman(win, x, y)
int win;
double x, y;
{
  newpen(win, 1);
  fillarc(win, x, y, 20.0, 17.0, 0.0, 360.0, 1);
  fillarc(win, x, y-40.0, 30.0, 25.0, 0.0, 360.0, 1);
  newpen(win, 0);
  fillarc(win, x-8, y+3, 5.0, 5.0, 0.0, 360.0, 1);
  fillarc(win, x+8, y+3, 5.0, 5.0, 0.0, 360.0, 1);

  
  return(0);
}

int main() {
  int win, i, seed;
  double sx[20],sy[20],ss[20];

  printf("please set the seed :");
  scanf("%d",&seed);
  srand(seed);  /* seed の設定 */

  for(i=0; i<20; i++) { /* 雪の位置を決める */
    sx[i]=(double)(rand()%400);
    sy[i]=(double)(rand()%400)+400;
    ss[i]=(double)(rand()%3)+3; /* 落下速度 */
  };

  win=gopen(400,400);  /* 描画ウィンドウを開く */
  winname(win, "snow"); /* 名前をつける */

  while(1) {  /* 永遠に繰り返し */

    newpen(win, 1);
    for(i=0; i<20; i++) { /* 雪を描く */
      fillrect(win, sx[i]-2.0, sy[i]-2.0, 4.0, 4.0);
      sy[i]=sy[i]-ss[i];
      if(sy[i]<2) {
	sx[i]=(double)(rand()%400);
	sy[i]=400;
	ss[i]=(double)(rand()%3)+3;
      };
    };
    snowman(win, 350.0, 80.0);
    usleep(60000);
    gclr(win);
  };


}
  
