home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / FFILLY / PLA010 / PLA010.TFY < prev    next >
Text File  |  1996-12-11  |  2KB  |  92 lines

  1.  
  2. #info INAM "惑星の運動 - 楕円軌道"
  3. #info ICMT "飽きるまで眺めよう。右クリックで終了します。"
  4. #info ISBJ "惑星の公転シュミレートだよん。"
  5. #info IART "もりきゅう"
  6. #info ICOP "もりきゅう"
  7. #info ICOP "Copy Right (c) 1996 もりきゅう"
  8. #info VIDO "640x400; 256"
  9. #info GRPC "もりきゅう,VZF07161@niftyserve.or.jp"
  10.  
  11. #define WHITE 0xffffff
  12.  
  13. #include "MakeWin.tfy"
  14.  
  15. int xCenter, yCenter;
  16. real DT;
  17.  
  18. main()
  19. {
  20.   int pSun, cSun, xSun, ySun;
  21.   int i, count, CWDLen;
  22.   str IniName, BmpName, sBuff;
  23.   real PX, PY, VX, VY;
  24.  
  25.   IniName = "Planet.ini";
  26.   SetPaintColor(WHITE);
  27.  
  28.   CapTitle(" 惑星の運動 - 楕円軌道 ");
  29.   MakeMainWin("Space.bmp");
  30.  
  31.   pSun = LoadPic("Sun.bmp");
  32.  
  33.   xCenter = PicWidth(pMain) / 2;
  34.   yCenter = PicHeight(pMain) / 2;
  35.  
  36.   DT = 0.08;
  37.  
  38.   xSun = xCenter - PicWidth(pSun) / 2;
  39.   ySun = yCenter - PicHeight(pSun) / 2;
  40.  
  41.   cSun = PutCast(pSun, pMain, xSun, ySun, WHITE);
  42.  
  43.   count = GetIniInt("Planet", "Count", 0, IniName);
  44.   for( i=0 ; i<count ; i=i+1 ) {
  45.     sBuff = GetIniStr("Planet", StrPrint("Pla%.2ld", i), "", IniName);
  46.     BmpName = SubStr(sBuff, 0, 12);
  47.     PX = StrtoReal( SubStr(sBuff, 12, 5) );
  48.     PY = StrtoReal( SubStr(sBuff, 17, 5) );
  49.     VX = StrtoReal( SubStr(sBuff, 22, 5) );
  50.     VY = StrtoReal( SubStr(sBuff, 27, 5) );
  51.     SetPlanet(BmpName, PX, PY, VX, VY);
  52.   }
  53. }
  54.  
  55. SetPlanet(str BmpName, real PX, real PY, real VX, real VY)
  56. {
  57.   int xPla, yPla;
  58.   int xpos, ypos;
  59.   int pPla, cPla;
  60.   real AX, AY;
  61.  
  62.   pPla = LoadPic(BmpName);
  63.   xPla = xCenter + RealtoInt(PX * 50.0);
  64.   yPla = yCenter - RealtoInt(PY * 50.0);
  65.   xpos = xpos - PicWidth(pPla) / 2;
  66.   ypos = ypos - PicHeight(pPla) / 2;
  67.   cPla = PutCast(pPla, pMain, xpos, ypos, WHITE);
  68.  
  69.   AX = -PX / Pow( Pow(PX, 2.0) + Pow(PY, 2.0), 1.5);
  70.   AY = -PY / Pow( Pow(PX, 2.0) + Pow(PY, 2.0), 1.5);
  71.  
  72.   mes( TIME ) {
  73.     step(2) {
  74.       VX = VX + AX * DT;
  75.       VY = VY + AY * DT;
  76.       PX = PX + VX * DT;
  77.       PY = PY + VY * DT;
  78.  
  79.       xPla = xCenter + RealtoInt(PX * 50.0);
  80.       yPla = yCenter - RealtoInt(PY * 50.0);
  81.       xpos = xPla - PicWidth(pPla) / 2;
  82.       ypos = yPla - PicHeight(pPla) / 2;
  83.       MoveCast(cPla, pPla, xpos, ypos);
  84.       DrawCircle(pBack, xPla-1, yPla-1, xPla+1, yPla+1, 0, 0);
  85.  
  86.       AX = -PX / Pow( Pow(PX, 2.0) + Pow(PY, 2.0), 1.5);
  87.       AY = -PY / Pow( Pow(PX, 2.0) + Pow(PY, 2.0), 1.5);
  88.     }
  89.   }
  90. }
  91.  
  92.