]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/samples/rain.adb
ncurses 4.2
[ncurses.git] / Ada95 / samples / rain.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                       GNAT ncurses Binding Samples                       --
4 --                                                                          --
5 --                                   Rain                                   --
6 --                                                                          --
7 --                                 B O D Y                                  --
8 --                                                                          --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998 Free Software Foundation, Inc.                        --
11 --                                                                          --
12 -- Permission is hereby granted, free of charge, to any person obtaining a  --
13 -- copy of this software and associated documentation files (the            --
14 -- "Software"), to deal in the Software without restriction, including      --
15 -- without limitation the rights to use, copy, modify, merge, publish,      --
16 -- distribute, distribute with modifications, sublicense, and/or sell       --
17 -- copies of the Software, and to permit persons to whom the Software is    --
18 -- furnished to do so, subject to the following conditions:                 --
19 --                                                                          --
20 -- The above copyright notice and this permission notice shall be included  --
21 -- in all copies or substantial portions of the Software.                   --
22 --                                                                          --
23 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
24 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
25 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
26 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
27 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
28 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
29 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
30 --                                                                          --
31 -- Except as contained in this notice, the name(s) of the above copyright   --
32 -- holders shall not be used in advertising or otherwise to promote the     --
33 -- sale, use or other dealings in this Software without prior written       --
34 -- authorization.                                                           --
35 ------------------------------------------------------------------------------
36 --  Author: Laurent Pautet <pautet@gnat.com> 1997 (modified by J.Pfeifer)
37 --  Version Control
38 --  $Revision: 1.3 $
39 --  Binding Version 00.93
40 ------------------------------------------------------------------------------
41 --                                                                          --
42 with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
43 with Status; use Status;
44 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
45
46 procedure Rain is
47
48    Visibility : Cursor_Visibility;
49
50    subtype X_Position is Line_Position;
51    subtype Y_Position is Column_Position;
52
53    Xpos    : array (1 .. 5) of X_Position;
54    Ypos    : array (1 .. 5) of Y_Position;
55
56    N : Integer;
57
58    G : Generator;
59
60    Max_X, X : X_Position;
61    Max_Y, Y : Y_Position;
62
63    procedure Next (J : in out Integer);
64    procedure Cursor (X : X_Position; Y : Y_Position);
65
66    procedure Next (J : in out Integer) is
67    begin
68       if J = 5 then
69          J := 1;
70       else
71          J := J + 1;
72       end if;
73    end Next;
74
75    procedure Cursor (X : X_Position; Y : Y_Position) is
76    begin
77       Move_Cursor (Line => X, Column => Y);
78    end Cursor;
79    pragma Inline (Cursor);
80
81 begin
82
83    Init_Screen;
84    Set_NL_Mode;
85    Set_Echo_Mode (False);
86
87    Visibility := Invisible;
88    Set_Cursor_Visibility (Visibility);
89
90    Max_X := Lines - 5;
91    Max_Y := Columns - 5;
92
93    for I in Xpos'Range loop
94       Xpos (I) := X_Position (Float (Max_X) * Random (G)) + 2;
95       Ypos (I) := Y_Position (Float (Max_Y) * Random (G)) + 2;
96    end loop;
97
98    N := 1;
99    while Process.Continue loop
100
101       X := X_Position (Float (Max_X) * Random (G)) + 2;
102       Y := Y_Position (Float (Max_Y) * Random (G)) + 2;
103
104       Cursor (X, Y);
105       Add (Ch => '.');
106
107       Cursor (Xpos (N), Ypos (N));
108       Add (Ch => 'o');
109
110       --
111       Next (N);
112       Cursor (Xpos (N), Ypos (N));
113       Add (Ch => 'O');
114
115       --
116       Next (N);
117       Cursor (Xpos (N) - 1, Ypos (N));
118       Add (Ch => '-');
119       Cursor (Xpos (N), Ypos (N) - 1);
120       Add (Str => "|.|");
121       Cursor (Xpos (N) + 1, Ypos (N));
122       Add (Ch => '-');
123
124       --
125       Next (N);
126       Cursor (Xpos (N) - 2, Ypos (N));
127       Add (Ch => '-');
128       Cursor (Xpos (N) - 1, Ypos (N) - 1);
129       Add (Str => "/\\");
130       Cursor (Xpos (N), Ypos (N) - 2);
131       Add (Str => "| O |");
132       Cursor (Xpos (N) + 1, Ypos (N) - 1);
133       Add (Str => "\\/");
134       Cursor (Xpos (N) + 2, Ypos (N));
135       Add (Ch => '-');
136
137       --
138       Next (N);
139       Cursor (Xpos (N) - 2, Ypos (N));
140       Add (Ch => ' ');
141       Cursor (Xpos (N) - 1, Ypos (N) - 1);
142       Add (Str => "   ");
143       Cursor (Xpos (N), Ypos (N) - 2);
144       Add (Str => "     ");
145       Cursor (Xpos (N) + 1, Ypos (N) - 1);
146       Add (Str => "   ");
147       Cursor (Xpos (N) + 2, Ypos (N));
148       Add (Ch => ' ');
149
150       Xpos (N) := X;
151       Ypos (N) := Y;
152
153       Refresh;
154       Nap_Milli_Seconds (50);
155    end loop;
156
157    Visibility := Normal;
158    Set_Cursor_Visibility (Visibility);
159    End_Windows;
160
161 end Rain;