Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,19 +0,0 @@
generic
type Float_Type is digits <>;
Gravitation : Float_Type;
package Pendulums is
type Pendulum is private;
function New_Pendulum (Length : Float_Type;
Theta0 : Float_Type) return Pendulum;
function Get_X (From : Pendulum) return Float_Type;
function Get_Y (From : Pendulum) return Float_Type;
procedure Update_Pendulum (Item : in out Pendulum; Time : in Duration);
private
type Pendulum is record
Length : Float_Type;
Theta : Float_Type;
X : Float_Type;
Y : Float_Type;
Velocity : Float_Type;
end record;
end Pendulums;

View file

@ -1,38 +0,0 @@
with Ada.Numerics.Generic_Elementary_Functions;
package body Pendulums is
package Math is new Ada.Numerics.Generic_Elementary_Functions (Float_Type);
function New_Pendulum (Length : Float_Type;
Theta0 : Float_Type) return Pendulum is
Result : Pendulum;
begin
Result.Length := Length;
Result.Theta := Theta0 / 180.0 * Ada.Numerics.Pi;
Result.X := Math.Sin (Theta0) * Length;
Result.Y := Math.Cos (Theta0) * Length;
Result.Velocity := 0.0;
return Result;
end New_Pendulum;
function Get_X (From : Pendulum) return Float_Type is
begin
return From.X;
end Get_X;
function Get_Y (From : Pendulum) return Float_Type is
begin
return From.Y;
end Get_Y;
procedure Update_Pendulum (Item : in out Pendulum; Time : in Duration) is
Acceleration : constant Float_Type := Gravitation / Item.Length *
Math.Sin (Item.Theta);
begin
Item.X := Math.Sin (Item.Theta) * Item.Length;
Item.Y := Math.Cos (Item.Theta) * Item.Length;
Item.Velocity := Item.Velocity +
Acceleration * Float_Type (Time);
Item.Theta := Item.Theta +
Item.Velocity * Float_Type (Time);
end Update_Pendulum;
end Pendulums;

View file

@ -1,24 +0,0 @@
with Ada.Text_IO;
with Ada.Calendar;
with Pendulums;
procedure Main is
package Float_Pendulum is new Pendulums (Float, -9.81);
use Float_Pendulum;
use type Ada.Calendar.Time;
My_Pendulum : Pendulum := New_Pendulum (10.0, 30.0);
Now, Before : Ada.Calendar.Time;
begin
Before := Ada.Calendar.Clock;
loop
Delay 0.1;
Now := Ada.Calendar.Clock;
Update_Pendulum (My_Pendulum, Now - Before);
Before := Now;
-- output positions relative to origin
-- replace with graphical output if wanted
Ada.Text_IO.Put_Line (" X: " & Float'Image (Get_X (My_Pendulum)) &
" Y: " & Float'Image (Get_Y (My_Pendulum)));
end loop;
end Main;