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

#define MAXR 200.0 // 描画する円の最大半径
#define MAXNUM 30 // 保持できる円の最大数

int main() {
  int win, code, type, i, pos;
  double x[MAXNUM], y[MAXNUM], r[MAXNUM], tempx, tempy;
  
  win=gopen(400,400);
  gsetnonblock(ENABLE); // ノンブロッキングモードに
  for(i=0; i<MAXNUM; i++) r[i]=0.0; // 描画する円の半径をゼロに
  pos=0; // まずはゼロポジションから待ち受け
  while( 1 ) {
    gclr(win); 
    if( ggetxpress( &type, &code, &tempx, &tempy) == win ) {
      switch( type ) {
        case KeyPress: // キー入力だったらプログラム終了
          gclose(win);
          return 0;
        case ButtonPress:  // マウスクリックだった
          r[pos]=1.0; // 描画する円の半径を増やす
          x[pos]=tempx; y[pos]=tempy; // 値を保持
          pos=(pos+1)%MAXNUM; // ポジションを次に移動して待つ
          break;
      }
    }
    for(i=0; i<MAXNUM; i++) {
      if( r[i] > 0.0 ) {
        newhsvcolor(win, 0, 255, 255 * (1.0 - r[i] / MAXR));
        drawcirc(win, x[i], y[i], r[i], r[i]); // 半径がゼロで無ければ描画
        r[i]+=1.0; // 径を大きくする
        y[i]-=0.03 * (r[i]-40.0); // 少しだけ上に進んで、以降下げる
        if( r[i] > MAXR ) r[i]=0.0; // 大きくなりすぎたら中止
      }
    }
    msleep(10);
  }

}
