{$A-,B-,D+,E+,F+,G-,I+,L+,N+,O-,P-,Q-,R-,S+,T-,V-,X+}
{$M 16384,0,655360}
Uses Crt,Graph;
Const
 G = 6.672e-11;
 {‡¥¬«ï}                    {‹ã­ }
 Me = 5.578e24*G;           Mm = 7.25e22*G;    {¬ áá ,ª£}
 Re = 6371000.0;            Rm = 384e6;        {à ¤¨ãá,¬}
                            Vm = 1024.0;       {m/c}
                            Wm=Vm/Rm;          {1/c}
 m =2000000;
 Ra = Rm/2;
 Ft = 5500;
 Va0 = 600;
 dltt : real = 20000;      {˜ £ ¨­â¥£à¨à®¢ ­¨ï}
 {íªà ­}
 Xwa = 0;         Ywa = 0;
 Xwb = 465;       Ywb = 349;
 Xmin = -1.5*Rm;  Ymin=Xmin;   {¬¨à®¢ë¥ ª®®à¤¨­ âë}
 Xmax=-Xmin;      Ymax=-Ymin;
 Kwx=(Xwb-Xwa)/(Xmax-Xmin);    {¬ áèâ ¡}
 Kwy=(Ywb-Ywa)/(Ymax-Ymin);

Function GetX(X:real): integer;
 Begin
  GetX:=Xwa+Round((X-Xmin)*Kwx);
 End;
Function GetY(Y:real): integer;
 Begin
  GetY:=Ywb-Round((Y-Ymin)*Kwy);
 End;
function FloatToStr(r: real; n,m: word): string;
var s : string;
Begin Str(r:n:m,s); FloatToStr:=s;
End;
procedure OutStr(x,y: integer; Ls,cf,ct: word; s: string);
Begin SetFillStyle(1,cf); SetColor(ct); Bar(x,y,x+8*Ls+3,y+10);
  SetTextJustify(0,2); SetTextStyle(0,0,1); OutTextXY(x+1,y+1,s);
End;
Procedure ShowMoon(X,Y: real);
var Xa,Ya : integer;
 Begin SetWriteMode(1);
  SetColor(Yellow); Xa:=GetX(X); Ya:=GetY(Y);
  MoveTo(Xa,Ya-4); LineTo(Xa-5,Ya); LineTo(Xa,Ya+4);
  LineTo(Xa+5,Ya); LineTo(Xa,Ya-4);
  SetWriteMode(0); PutPixel(Xa,Ya,Yellow);
 End;

Procedure Show(X,Y: real; C,W: word);
var Xa,Ya : integer;
 Begin SetWriteMode(1);
  SetColor(C); Xa:=GetX(X); Ya:=GetY(Y);
  Line(Xa-W,Ya,Xa+W,Ya);Line(Xa,Ya-W,Xa,Ya+W);
  SetWriteMode(0); PutPixel(Xa,Ya,C);
 End;

Procedure Stars;
Var
  I : word;
Begin
  randomize;
  For I:=1 to 300 do putpixel(random(463), random(348), random(16)+1);
End;

var
 Driver,Mode,step,Xa,Ya,k:integer;
 x,y,Xm,Ym,Fi,t,dt,Ke,Km,rae,ram,Vx,Vy,Vx1,Vy1:real;
 ch : char;
begin
 driver:=Detect;
 InitGraph(Driver,Mode,'');
 Rectangle(Xwa,Ywa,Xwb,Ywb);
 SetColor(LightBlue); SetFillStyle(1,LightBlue);
 stars;
 PieSlice(GetX(0),GetY(0),0,360,10);
 OutStr(470,30,6,0,10,'‚à¥¬ï:       h');
 OutStr(470,40,6,0,10,'V=           m/c');
 OutStr(470,50,6,0,10,'RE=          km');
 OutStr(470,60,6,0,10,'RM=          km');
 ke:=3/4;
 if ParamCount>=1 then Val(ParamStr(1),ke,k);
 if ke>1.25 then ke:=1.25 else if ke<-1.25 then ke:=-1.25;
 x:=ke*Rm; y:=0;
 Show(X,Y,LightRed,3);
 Vx:=Va0;
 Vy:=Sqrt(9.81*Sqr(Re)/x);
 Xm:=Rm; Ym:=0; ShowMoon(Xm,Ym);
 t:=0;
 ch:=readkey;
 Repeat
  inc(step);
  rae:=Sqrt(x*x+y*y);
  ram:=Sqrt(Sqr(x-xm)+Sqr(y-ym));
  dt:=dltt;
  if (rae<10.0e6)or(ram<5.0e6) then dt:=dltt*0.1
     else if (rae<50.0e6)or(ram<25.0e6) then dt:=dltt*0.25
       else if (rae<100.0e6)or(ram<50.0e6) then dt:=dltt*0.5;
  t:=t+dt;
  {Moon}
  ShowMoon(Xm,Ym);
  Fi:=Wm*t; Xm:=Rm*cos(Fi); Ym:=Rm*sin(Fi);
  ShowMoon(Xm,Ym);
  {KA}
  If ch=#32 then begin x:=ke*rm; y:=0; end;
  Show(X,Y,LightRed,3);
  Ke:=Me/(rae*rae*rae);
  Km:=Mm/(ram*ram*ram);
  If step mod 10 = 0 then begin
  Vx1:=Vx-dt*(Ke*x+Km*(x-Xm)+Ft/m);
  Vy1:=Vy-dt*(Ke*y+Km*(y-Ym)+Ft/m);
  end else
  begin
  Vx1:=Vx-dt*(Ke*x+Km*(x-Xm));
  Vy1:=Vy-dt*(Ke*y+Km*(y-Ym));
  end;
  x:=x+dt*(Vx1+Vx)*0.5;
  y:=y+dt*(Vy1+Vy)*0.5;
  Show(X,Y,LightRed,3);
  Vx:=Vx1; Vy:=Vy1;
  OutStr(520,30,6,0,14,FloatToStr(Round(t/3600),5,0));
  OutStr(520,40,6,0,14,FloatToStr(Sqrt(sqr(vx)+sqr(vy)),6,0));
  OutStr(490,50,10,0,14,FloatToStr(rae*0.001,10,0));
  OutStr(490,60,10,0,14,FloatToStr(ram*0.001,10,0));
 Until ch=#27;
end.
