-
Notifications
You must be signed in to change notification settings - Fork 0
/
Balls.pas
134 lines (111 loc) · 2.17 KB
/
Balls.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{ Made by Frank }
uses
CRT, Graph;
type
TBall = record
bc, br : integer;
bx, by : integer;
dx, dy : integer;
mx, my : integer;
nx, ny : integer;
gl, gu : boolean;
end;
const
nBall = 900;
var
Balls : array[1..nBall] of TBall;
function randomColor : integer;
var
cs : android_graphics_Color;
begin
randomColor := cs.rgb(random(224) + 32,
random(224) + 32, random(224) + 32);
end;
procedure MoveBall(var aBall : TBall);
begin
with aBall do
begin
if gl then bx := bx - dx
else bx := bx + dx;
if gu then by := by - dy
else by := by + dy;
if bx < nx then
begin
bx := nx;
gl := false;
end;
if bx > mx then
begin
bx := mx;
gl := true;
end;
if by < ny then
begin
by := ny;
gu := false;
end;
if by > my then
begin
by := my;
gu := true;
end;
end;
end;
procedure DrawBall(aBall : TBall);
begin
with aBall do
begin
SetColor(bc);
SetFillStyle(SolidFill, bc);
PieSlice(bx, by, 0, 360, br);
end;
end;
procedure InitBalls(w, h : integer);
var
i : integer;
begin
for i := 1 to nBall do
with Balls[i] do
begin
bc := randomColor;
br := random(34) + 23;
bx := random(w - br) + br;
by := random(h - br) + br;
dx := random(20) + 1;
dy := random(20) + 1;
mx := w - br - 1;
my := h - br - 1;
nx := br + 1;
ny := br + 1;
gl := random(2) = 0;
gu := random(2) = 0;
end;
end;
var
cs : android_graphics_Color;
i, c : integer;
mx, my : integer;
begin
setBufferEnable(true);
InitGraph(detect, 0, '');
mx := GetMaxX;
my := GetMaxY;
Randomize;
InitBalls(mx, my);
SetLineStyle(SolidLn, 0, ThickWidth);
while not keyPressed do
begin
SetColor(15);
c := cs.argb(100, 1, 1, 1);
setFillStyle(solidFill, c);
Bar(0, 0, mx, my);
SetTextStyle(boldFont, horizDir, 9);
SetTextJustify(centerText, centerText);
outTextXY(mx div 2, my div 2, '');
for i := 1 to nBall do
DrawBall(Balls[i]);
for i := 1 to nBall do
MoveBall(Balls[i]);
drawBuffer;
end;
end.