/*
 layer 機能を使わないアニメーションのサンプル
*/

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

int main() {
  int win, seed, i, c[30];
  double x[30], y[30], w, dx[30], dy[30];

  printf("random seed = ");
  scanf("%d",&seed);
  srand(seed); 

  win=gopen(400,400);  /* 描画ウィンドウを開く */
  winname(win, "sample 1"); /* 名前をつける */
  gsetbgcolor(win, "white"); /* 背景色を白に */

  w=30.0;                    /* 球の半径を決める */
  for(i=0; i< 30; i++) {
    x[i]=(double)(rand() % 100) + 175.0;   /* x 座標位置はランダム */
    y[i]=(double)(rand() % 100) + 175.0;   /* y 座標位置もランダム */
    dx[i]=(double)(rand() % 15 + 2) / 40.0 * w;  /* x 方向の移動速度 */
    dy[i]=(double)(rand() % 15 + 2) / 40.0 * w;  /* y 方向の移動速度 */
    c[i]= i%10 + 1; /* 色を設定 */
  }

  while(1) {
    gclr(win);                 /* 画面を消去 */
    for(i=0; i< 30; i++) {
      newpen(win, c[i]); 
      fillarc(win, x[i], y[i], w, w, 0.0, 360.0, 1); /* 球を描く */
      y[i]+= dy[i];  
      if( y[i] < 0.0 || y[i] > (400.0 - w) ) dy[i]*=(-1.0);
      x[i]+= dx[i];  
      if( x[i] < 0.0 || x[i] > (400.0 - w) ) dx[i]*=(-1.0);
    }
    msleep(50);                /* 少し待つ */
  }

  /* このプログラムは終了しないので return 0; などは無し */

}


