{$X+}

Uses Crt , Graph;

Const
     g = 9.81;
     l = 40;
   Col = White;

 Alpha : Real = Pi / 4 ;
 Step : Real = Pi /100 ;

Var
 X , Y : Integer;
Function Transform2Str(a:real):string;
Var
  s:string;
Begin
  Str(a, S); Transform2str := s;
End;
Procedure SetGraph;

 Var
  Driver , Mode : Integer;
         Result : ShortInt;
 Begin
  DetectGraph ( Driver , Mode );
   InitGraph ( Driver , Mode , 'D:\TP\BGI' );
  Result := GraphResult;
   If Result <> GrOK then
        begin
         WriteLn ( ' Warning ! Graphic error number  ', Result ,' ,' );
         WriteLn ( ' ' , GraphErrorMsg ( Result ) , '! ');
         Halt ( 0 );
        end;
 End;
Procedure DrawGun ( Color : Integer );
 Begin
   SetFillStyle ( 1 , Color );
   MoveTo ( 0 , GetMaxY );
   Bar ( 0 , GetMaxY , l div 4 , GetMaxY - l div 4 );
   SetColor ( Color );
  LineRel ( Round( 1.2 * l * cos ( Alpha ) ), - Round ( 1.2 * l * sin ( Alpha ) ) );
 End;

Procedure Control;
  Var Ch : Char;
 Begin
  SetLineStyle ( SolidLn , 0 , ThickWidth );
   Randomize;
  Repeat
   Ch := ReadKey;
     SetColor ( Black );
    MoveTo ( 0 , GetMaxY );
   LineRel ( Round( 1.2 * l * cos ( Alpha ) ), - Round ( 1.2 * l * sin ( Alpha ) ) );
    If Ch = #75 then Alpha := Alpha + Step;
    If Ch = #77 then Alpha := Alpha - Step;
    If Alpha > Pi / 2 then Alpha := Pi / 2;
    If Alpha < 0 then Alpha := 0;
   DrawGun ( Col );
    OutTextXY ( 0 , 0 , 'Alpha = ' + float2str(180*alpha/pi));
  Until False;
 End;

 Begin
  SetGraph;
   DrawGun ( Col );
  Control;
 End.
