#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "GrWin.h"

/* アニメーション */

int main()
{
  float x, y, dx, dy;

  printf("dx, dy =");
  scanf("%f %f", &dx, &dy); /* ステップごとの進行速度 */

  GWopen(0);
  GWindow(0.0, 0.0, 200.0, 200.0);

  x=80.0; y=30.0; /* 最初の位置 */

  while(1) {
    GWxrect(10.0, 20.0, 160.0, 160.0, 13); /* 枠を表示 */
    if( (x >= 150.0) || (x <= 10.0) ) {
      /* 左右の壁に当たったら方向転換 */
      dx= -1.0 * dx;
    };
    x+=dx; /* x 軸方向にワンステップ進む */
    if( (y >= 150.0) || (y <= 20.0) ) {
      /* 上下の壁に当たったら方向転換 */
      dy= -1.0 * dy;
    };
    y+=dy; /* y 軸方向にワンステップ進む */
    GWsrect(x, y, x+10.0, y+10.0, 16);
    GWsleep(20);
    GWclear(-1);
  };
}

