Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Animate-a-pendulum/Ada/animate-a-pendulum-1.ada
Normal file
19
Task/Animate-a-pendulum/Ada/animate-a-pendulum-1.ada
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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;
|
||||
38
Task/Animate-a-pendulum/Ada/animate-a-pendulum-2.ada
Normal file
38
Task/Animate-a-pendulum/Ada/animate-a-pendulum-2.ada
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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;
|
||||
24
Task/Animate-a-pendulum/Ada/animate-a-pendulum-3.ada
Normal file
24
Task/Animate-a-pendulum/Ada/animate-a-pendulum-3.ada
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue