/*
    第2種情報処理技術者試験    平成12年度・春期・午後 問7
                                BohYoh Shibata PREPARATION
*/

#include <math.h>
#define TRUE    1
#define FALSE   0

typedef  struct  {
  int    Ready;
  int    Hour, Minute, Second;
  int    Cx, Cy;
  int    Radius;
  int    PlateX[ 360 ], PlateY[ 360 ];
} ACLOCK;

void    DrawLine( int sx, int sy, int ex, int ey, int Width );
void    DrawCircle( int x, int y, int r );

void    DisplayClock( ACLOCK *pt )
{
 const  double Rad      = 3.14159265359 / 180.0;
 const  int  LargeMark  = 6;
 const  int  SmallMark  = 2;
 const  int  HourHand   = 7;
 const  int  MinuteHand = 3;
 const  int  SecondHand = 1;
 int    angle, Size, Hx, Hy, w, x, y;

 if ( pt->Ready == FALSE ) {    /* 座標を計算する */
      for ( w = -90, x = y = 0; w < 270; w++, x++, y++ ) {
          pt->PlateX[x] = pt->Cx + (int)(pt->Radius*cos(w*Rad));
          pt->PlateY[y] = pt->Cy + (int)(pt->Radius*sin(w*Rad));
      }
      pt->Ready = TRUE;
 }

 for ( angle = 0; angle < 360; angle += 6 ){   /* 目盛りを描画する */
      if ( angle % 30 == 0 ) Size = LargeMark;
      else                   Size = SmallMark;
      DrawCircle( pt->PlateX[angle], pt->PlateY[angle], Size);
 }

 angle = pt->Second*6;                         /* 秒針を描く */
 DrawLine( pt->Cx, pt->Cy,
           pt->PlateX[angle], pt->PlateY[angle], SecondHand );

 angle = pt->Minute*6 + pt->Second/10;         /* 分針を描く */
 DrawLine( pt->Cx, pt->Cy,
           pt->PlateX[angle], pt->PlateY[angle], MinuteHand );

 if ( pt->Hour >= 12 ) pt->Hour -= 12;
 angle = pt->Hour*30 + pt->Minute/2 ;          /* 時針を描く */
 Hx = ( pt->Cx + pt->PlateX[angle] ) / 2;
 Hx = ( Hx + pt->PlateX[angle]) / 2;
 Hy = ( pt->Cy + pt->PlateY[angle] ) / 2;
 Hy = ( Hy + pt->PlateY[angle] ) / 2;
 DrawLine( pt->Cx, pt->Cy, Hx, Hy, HourHand );
 DrawCircle( pt->Cx, pt->Cy, pt->Radius / 10 ); /* 中心軸を描く */
}