#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, y, size;
  int c, seed;

  printf("random seed :");
  scanf("%d", &seed);
  srand(seed);

  GWopen(0);
  GWindow(0.0, 0.0, 200.0, 200.0);

  size=10.0; /* 基本的なサイズ */
  x=200.0;
  y=rand()%200+10.0; /* 登場位置 */
  c=16; /* 体の色 (16:青) */

  /* ループはじまり */
  while( 1 ) {
    if( x < 10.0 ) { /* 端まで到達 */
      x=200.0;
      y=rand()%200+10.0;
      c=rand()%19;
    } else {
      x-=2.0;
    }
    fish(x, y, size, c);
    GWsleep(80);
    GWclear(-1);
  }

  return 0;
}

