Advertisement
WarPie90

Simba 1.5 - Planetary rotation around sun

Oct 29th, 2023 (edited)
1,772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.34 KB | None | 0 0
  1. program new;
  2. {$R-}
  3.  
  4. const
  5.   SPEEDSCALE := 500;
  6.   G = 6.674*10**-11;
  7.   Middle: TPoint = [500,500];
  8.  
  9. type
  10.   TPlanet = record
  11.     Distance, Diameter, Mass: Double;
  12.  
  13.     Pos: record Distance, Angle: Single; end;
  14.     Color: TColor;
  15.     pathrad: Int32;
  16.   end;
  17.  
  18.  
  19. var
  20.   Sun: TPlanet;
  21.   image: TImage;
  22.   Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune: TPlanet;
  23.   year: Int32;
  24.  
  25. function TPlanet.Velocity(): Double;
  26. begin
  27.   Result := Sqrt((G*Sun.Mass) / (Self.Distance*1000));
  28. end;
  29.  
  30. function TPlanet.SizeScaled(): Int32;
  31. begin
  32.   Result := Max(1,Trunc(Self.Diameter ** 0.35 / 5));
  33. end;
  34.  
  35. function TPlanet.Tick(Image: TImage): TPoint;
  36. var
  37.   speed: Single;
  38.   size: Int32;
  39. begin
  40.   speed := Self.Velocity();
  41.   size  := Self.SizeScaled();
  42.  
  43.   if Self.Diameter = Earth.Diameter then
  44.   begin
  45.     if Modulo(Self.Pos.Angle + speed/Self.Distance*speedscale, 2*PI) <> Self.Pos.Angle + speed/Self.Distance*speedscale then
  46.       year += 1;
  47.  
  48.     Image.DrawText('Earth years: '+ ToStr(year), [50,50], $FFFFFF);
  49.   end;
  50.  
  51.   Self.Pos.Distance := Self.Distance ** 0.27;
  52.   Self.Pos.Angle := Modulo(Self.Pos.Angle + speed/Self.Distance*speedscale, 2*PI);
  53.  
  54.   Result.x := Round(Middle.x + Self.Pos.Distance * Cos(Self.Pos.Angle));
  55.   Result.y := Round(Middle.y + Self.Pos.Distance * Sin(Self.Pos.Angle));
  56.  
  57.   if Self.pathrad = 0 then Self.pathrad := Ceil(Result.DistanceTo(Middle));
  58.   image.DrawCircleAA(middle, Self.pathrad, $222222, 1);
  59.  
  60.   image.DrawCircleAA(Result, size, Self.Color, size);
  61. end;
  62.  
  63. procedure Update(Image: TImage);
  64. begin
  65.   Mercury.Tick(image); Venus.Tick(image); Earth.Tick(image); Mars.Tick(image);
  66.   Jupiter.Tick(image); Saturn.Tick(image); Uranus.Tick(image); Neptune.Tick(image);
  67. end;
  68.  
  69. var
  70.   tmp: TImage;
  71. begin
  72.   Sun.Diameter     := 696340*2;
  73.   Sun.Mass         := 2*10**30;
  74.   Sun.Distance     := 0;
  75.  
  76.  
  77.   Mercury.Diameter := 2440*2;
  78.   Mercury.Mass     := 3.3010*10**23;
  79.   Mercury.Distance := 57.9*10**6;
  80.   Mercury.Color    := Colors.SLATEGREY;
  81.  
  82.   Venus.Diameter   := 6052*2;
  83.   Venus.Mass       := 4.1380*10**24;
  84.   Venus.Distance   := 108.2*10**6;
  85.   Venus.Color      := Colors.PALE_VIOLETRED;
  86.  
  87.   Earth.Diameter   := 6371*2;
  88.   Earth.Mass       := 5.97*10**24;
  89.   Earth.Distance   := 149.6*10**6;
  90.   Earth.Color      := Colors.SKYBLUE;
  91.  
  92.   Mars.Diameter    := 3390*2;
  93.   Mars.Mass        := 6.4273*10**23;
  94.   Mars.Distance    := 228.0*10**6;
  95.   Mars.Color       := Colors.RED;
  96.  
  97.   Jupiter.Diameter := 69911*2;
  98.   Jupiter.Mass     := 1.89852*10**27;
  99.   Jupiter.Distance := 778.5*10**6;
  100.   Jupiter.Color    := Colors.MEDIUM_BLUE;
  101.  
  102.   Saturn.Diameter  := 58232*2;
  103.   Saturn.Mass      := 5.6846*10**26;
  104.   Saturn.Distance  := 1432.0*10**6;
  105.   Saturn.Color    := Colors.BEIGE;
  106.  
  107.   Uranus.Diameter  := 25362*2;
  108.   Uranus.Mass      := 8.6819*10**25;
  109.   Uranus.Distance  := 2867.0*10**6;
  110.   Uranus.Color     := Colors.SKYBLUE;
  111.  
  112.   Neptune.Diameter := 24622*2;
  113.   Neptune.Mass     := 1.02431*10**26;
  114.   Neptune.Distance := 4515.0*10**6;
  115.   Neptune.Color    := Colors.DARK_BLUE;
  116.  
  117.   image := TImage.Create(1000,1000);
  118.  
  119.   while True do
  120.   begin
  121.     image.DrawCircleAA(Middle, Sun.SizeScaled(), $88FFFF, Sun.SizeScaled());
  122.     Update(image);
  123.     //tmp := image.ResizeBilinear(image.GetWidth() div 4, image.GetHeight() div 4);
  124.     image.Show(False);
  125.     //tmp.Free();
  126.     image.Clear();
  127.     //TerminateScript;
  128.   end;
  129.   image.Free();
  130. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement