slide: 1 copyright © adacore ten bouncing balls presented by quentin ochem university.adacore.com
TRANSCRIPT
![Page 1: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/1.jpg)
Slide: 1Copyright © AdaCore
Ten Bouncing BallsPresented by Quentin Ochem
university.adacore.com
![Page 2: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/2.jpg)
Slide: 2Copyright © AdaCore
{X’ = X + DxY’ = Y + Dy}
{X, Y}
![Page 3: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/3.jpg)
Slide: 3Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
![Page 4: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/4.jpg)
Slide: 4Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Checks if a value is within an range
![Page 5: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/5.jpg)
Slide: 5Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Moves using a vector
![Page 6: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/6.jpg)
Slide: 6Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Get access to random functions
![Page 7: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/7.jpg)
Slide: 7Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Initializes a generator to the default
![Page 8: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/8.jpg)
Slide: 8Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Value in [0.0 .. 1.0]
![Page 9: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/9.jpg)
Slide: 9Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Value in [0.0 .. 0.05]
![Page 10: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/10.jpg)
Slide: 10Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Value in [0.02 .. 0.07]
![Page 11: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/11.jpg)
Slide: 11Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Value in [0.02 .. 0.07] Value in [0.0 .. 1.0]
![Page 12: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/12.jpg)
Slide: 12Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Value in [0.02 .. 0.07] Value in {-1.0, 1.0}
![Page 13: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/13.jpg)
Slide: 13Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Value in {[-0.07 .. -0.02], [0.02 .. 0.07]}
![Page 14: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/14.jpg)
Slide: 14Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Declares an array type
![Page 15: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/15.jpg)
Slide: 15Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
The array in indexed by Integer
![Page 16: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/16.jpg)
Slide: 16Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
The array contains a number of elements to be specified at declaration
![Page 17: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/17.jpg)
Slide: 17Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
The array contains instances of Ball_Type
![Page 18: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/18.jpg)
Slide: 18Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Declare an array of type Ball_Array
![Page 19: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/19.jpg)
Slide: 19Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Gives boundaries between 1 and 10 (10 elements)
![Page 20: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/20.jpg)
Slide: 20Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Initializes the array through an aggreate
![Page 21: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/21.jpg)
Slide: 21Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Every value is initialized through the same expression
![Page 22: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/22.jpg)
Slide: 22Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Initializes each component through the same record aggregate
![Page 23: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/23.jpg)
Slide: 23Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
These will be recomputed for each element!
![Page 24: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/24.jpg)
Slide: 24Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Main is type Ball_Type is record Shape : Shape_Id; Dx, Dy : Float; end record; type Ball_Array is array (Integer range <>) of Ball_Type; Seed : Generator; Balls : Ball_Array (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 10.0, Blue), Dx => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0), Dy => (Random (Seed) * 0.05 + 0.02) * (if Random (Seed) > 0.5 then 1.0 else -1.0)));
procedure Iterate (V : in out Ball_Type) is begin if Get_X (V.Shape) not in -100.0 .. 100.0 then V.Dx := -V.Dx; end if; if Get_Y (V.Shape) not in -100.0 .. 100.0 then V.Dy := -V.Dy; end if; Set_X (V.Shape, Get_X (V.Shape) + V.Dx); Set_Y (V.Shape, Get_Y (V.Shape) + V.Dy); end Iterate; begin loop for B of Balls loop Iterate (B); end loop; delay 0.001; end loop; end Main;
Iterate through each element of Balls
![Page 25: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/25.jpg)
Slide: 25Copyright © AdaCore
Quiz
![Page 26: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/26.jpg)
Slide: 26Copyright © AdaCore
Identify the Errors
with Display; use Display;with Display.Basic; use Display.Basic;
procedure Main is type Ball_Type is record Shape : Shape_Id; X, Y : Float; Step : Float; end record;
type Ball_List is array (Integer) of Ball_Type;
List : Ball_List (1 .. 10) := ((Shape => New_Circle (0.0, 0.0, 5.0, Blue), X => 0.0, Y => 0.0, Step => 1.0));begin loop for B in List loop B.X := B.X + B.Step; end loop;
delay 0.001; end loop;end Main;
![Page 27: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/27.jpg)
Slide: 27Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;
procedure Main is type Ball_Type is record Shape : Shape_Id; X, Y : Float; Step : Float; end record;
type Ball_List is array (Integer) of Ball_Type;
List : Ball_List (1 .. 10) := ((Shape => New_Circle (0.0, 0.0, 5.0, Blue), X => 0.0, Y => 0.0, Step => 1.0));begin loop for B in List loop B.X := B.X + B.Step; end loop;
delay 0.001; end loop;end Main;
![Page 28: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/28.jpg)
Slide: 28Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;
procedure Main is type Ball_Type is record Shape : Shape_Id; X, Y : Float; Step : Float; end record;
type Ball_List is array (Integer) of Ball_Type;
List : Ball_List (1 .. 10) := ((Shape => New_Circle (0.0, 0.0, 5.0, Blue), X => 0.0, Y => 0.0, Step => 1.0));begin loop for B in List loop B.X := B.X + B.Step; end loop;
delay 0.001; end loop;end Main;
“range <>” needs to bespecified for an unconstrained array
![Page 29: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/29.jpg)
Slide: 29Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;
procedure Main is type Ball_Type is record Shape : Shape_Id; X, Y : Float; Step : Float; end record;
type Ball_List is array (Integer range <>) of Ball_Type;
List : Ball_List (1 .. 10) := ((Shape => New_Circle (0.0, 0.0, 5.0, Blue), X => 0.0, Y => 0.0, Step => 1.0));begin loop for B in List loop B.X := B.X + B.Step; end loop;
delay 0.001; end loop;end Main;
“others =>” is missing to specifythat a value is givento all objects
![Page 30: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/30.jpg)
Slide: 30Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;
procedure Main is type Ball_Type is record Shape : Shape_Id; X, Y : Float; Step : Float; end record;
type Ball_List is array (Integer range <>) of Ball_Type;
List : Ball_List (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 5.0, Blue), X => 0.0, Y => 0.0, Step => 1.0));begin loop for B in List loop B.X := B.X + B.Step; end loop;
delay 0.001; end loop;end Main;
“of” is the notationto iterate over theelements
![Page 31: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/31.jpg)
Slide: 31Copyright © AdaCore
with Display; use Display;with Display.Basic; use Display.Basic;
procedure Main is type Ball_Type is record Shape : Shape_Id; X, Y : Float; Step : Float; end record;
type Ball_List is array (Integer range <>) of Ball_Type;
List : Ball_List (1 .. 10) := (others => (Shape => New_Circle (0.0, 0.0, 5.0, Blue), X => 0.0, Y => 0.0, Step => 1.0));begin loop for B of List loop B.X := B.X + B.Step; end loop;
delay 0.001; end loop;end Main;
![Page 32: Slide: 1 Copyright © AdaCore Ten Bouncing Balls Presented by Quentin Ochem university.adacore.com](https://reader036.vdocuments.us/reader036/viewer/2022081501/5697c0131a28abf838ccc839/html5/thumbnails/32.jpg)
Slide: 32Copyright © AdaCore
university.adacore.com