#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "GrWin.h"

/* 星を動かす(サブルーチン+random+配列） */

int hosi(float x, float y, float size, int c) 
{
  
  /* いち */
  GWxline(x, y+6, x+3, y+6, c);

  /* に */
  GWxline(x+3, y+6, x+5, y+9, c);
 
  /*さん */
  GWxline(x+5,y+9,x+7,y+6,c);
   
  /*よん */
  GWxline(x+7,y+6,x+10,y+6, c);

  /*ご*/
 GWxline(x+10,y+6,x+8,y+3,c);
	
  /*ろく*/
  GWxline(x+8,y+3,x+9,y,c);
	
  /*なな*/
  GWxline(x+9,y,x+5,y+3,c);
	
  /*はち*/
  GWxline(x+5,y+3,x+1,y,c);
	
  /*きゅう*/
  GWxline(x+1,y,x+2,y+3,c);
	
  /*じゅう*/
  GWxline(x+2,y+3,x,y+6,c);
	
	return 0;
}
	

/*建物を描く(多角形 )*/

int tatemono()
{
  float points[35][2];
  /* いち */
 points[1][0]=0; points[1][1]=10;
  /* に */
 points[2][0]=20; points[2][1]=10;
  /*さん */
 points[3][0]=20; points[3][1]=20;
  /*よん */
 points[4][0]=30; points[4][1]=40;
  /*ご*/
 points[5][0]=40; points[5][1]=30;
  /*ろく*/
 points[6][0]=40; points[6][1]=40;
  /*なな*/
 points[7][0]=20; points[7][1]=40;
  /*はち*/
 points[8][0]=40; points[8][1]=50;
  /*きゅう*/
 points[9][0]=40; points[9][1]=60;
  /*じゅう*/
 points[10][0]=30; points[10][1]=60;
  /*じゅういち*/
 points[11][0]=49;points[11][1]=70;
  /*じゅうに*/
 points[12][0]=49;points[12][1]=90;
  /*じゅうさん*/
 points[13][0]=51;points[13][1]=90;
  /*じゅうよん*/
 points[14][0]=51;points[14][1]=70;
  /*じゅうご*/
 points[15][0]=70;points[15][1]=60;
  /*じゅうろく*/
 points[16][0]=60;points[16][1]=60;
  /*じゅうなな*/
 points[17][0]=60;points[17][1]=50;
  /*じゅうはち*/
 points[18][0]=70;points[18][1]=42;
  /*じゅうきゅう*/
 points[19][0]=70;points[19][1]=50;
  /*にじゅう*/
 points[20][0]=100;points[20][1]=50;
  /*にじゅういち*/
 points[21][0]=100;points[21][1]=80;
  /*にじゅうに*/
 points[22][0]=140;points[22][1]=80;
  /*にじゅうさん*/
 points[23][0]=140;points[23][1]=10;
  /*にじゅうよん*/
 points[24][0]=160;points[24][1]=30;
  /*にじゅうご*/
 points[25][0]=190;points[25][1]=10;
  /*にじゅうろく*/
 points[26][0]=190;points[26][1]=50;
  /*にじゅうなな*/
 points[27][0]=210;points[27][1]=50;
  /*にじゅうはち*/
 points[28][0]=210;points[28][1]=40;
  /*にじゅうきゅう*/
 points[29][0]=240;points[29][1]=40;
  /*さんじゅう*/
 points[30][0]=240;points[30][1]=70;
  /*さんじゅういち*/
 points[31][0]=270;points[31][1]=70;
  /*さんじゅうに*/
 points[32][0]=270;points[32][1]=10;
  /*さんじゅうさん*/
 points[33][0]=280;points[33][1]=30;
  /*さんじゅうよん*/
 points[34][0]=280;points[34][1]=-20;
  /*さんじゅうご*/
 points[35][0]=0;points[35][1]=-20;
 
  /*建物塗りつぶし*/
	GWsetpen(7,-1,-1,4);
	GWsetbrs(7,1,-1);
	GWpolygon(*points,36,0);

  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()%12+8; /*星の色 */
  };
  size=10.0; /* 基本的なサイズ */

  /* ループはじまり */
  while( 1 ) {
    for(i=0; i<10; i++) {
      if( y[i] < 10.0 ) { /* 端まで到達 */
        x[i]=rand()%200+10.0;
        y[i]=200.0;
        c[i]=rand()%19;
      } else {
        y[i]-=2.0;
      };
     hosi(x[i], y[i],size,  c[i]);
    };
  	 tatemono();
    GWsleep(600);
    GWclear(0);
  };
	
};
