#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "GrWin.h"

/* サカナを動かす(サブルーチン+random+配列） */

int fish(float x, float y, float size, int c) 
{
  float d;

  /* アタマ */
  GWxpie(x-size, y-size, x+size, y+size, 0.85, 0.3, c);

  /* 白目と黒目を入れる */
  GWscircle(x+size*0.4,  y-size*0.3,  x+size*0.8,  y+size*0.3, 19);
  GWscircle(x+size*0.45, y-size*0.25, x+size*0.75, y+size*0.25, 0);

  /* 胴骨 */
  for( d=0.0; d<0.8; d+=0.1 ) {
    GWxarc(x+size+(size*d), y-size, x+size*2.0+(size*d), y+size, 0.3,  0.4, 2);
  };
  
  /* しっぽ */
  GWxpie(x+size*0.8, y-size, x+size*2.6, y+size, 0.85, 0.3, c);

  return 0;
}	

int main()
{
  float x[10], y[10], size;
  int c[10], i, seed;

  printf("random seed :");
  scanf("%d", &seed);
  srand(seed);

  GWopen(0);
  GWindow(0.0, 0.0, 200.0, 200.0);

  for(i=0;i<10;i++) {
    x[i]=rand()%200+10.0; /* 登場位置 */
    y[i]=rand()%200+10.0;
    c[i]=rand()%19; /* 体の色 */
  };
  size=10.0; /* 基本的なサイズ */

  /* ループはじまり */
  while( 1 ) {
    for(i=0; i<10; i++) {
      if( x[i] < 10.0 ) { /* 端まで到達 */
        x[i]=200.0;
        y[i]=rand()%200+10.0;
        c[i]=rand()%19;
      } else {
        x[i]-=2.0;
      };
      fish(x[i], y[i], size, c[i]);
    };	
    GWsleep(80);
    GWclear(-1);
  };

  return 0;
}

