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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
ColorBox1: TColorBox;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
ball=class
R,x1,y1,dx,dy,Number:integer;
Col:Tcolor;
procedure XPYP(c:Tcanvas);
procedure XMYM(c:Tcanvas);
procedure XPYM(c:Tcanvas);
procedure XMYP(c:Tcanvas);
constructor Create;
end;
const
Nmax=100;
var
Form1: TForm1;
a:array [1..Nmax] of ball;
Xmax,Ymax:integer;
implementation
{$R *.dfm}
constructor ball.Create;
begin
x1:=random(xmax);
y1:=random(ymax);
dx:=1+random(5);
dy:=1+random(5);
r:=10+random(50);
col:=Form1.ColorBox1.Colors[3+random(20)]
end;
procedure ball.XPYP (c:Tcanvas);
begin
C.Brush.Color:=Form1.Color;
C.Pen.Color:=Form1.Color;
C.Ellipse(x1,y1,x1+r,y1+r);
x1:=x1+dx;
y1:=y1+dy;
if (x1+r>xmax)and (y1+r>ymax) then
begin
Number:=3;
exit;
end;
if (x1+r>xmax)and (y1+r<ymax) then
begin
Number:=2;
exit;
end;
if (x1+r<xmax)and (y1+r>ymax) then
begin
Number:=1;
exit;
end;
C.Brush.Color:=Col;
C.Ellipse(x1,y1,x1+r,y1+r)
end;
procedure ball.XPYM (c:Tcanvas);
begin
C.Brush.Color:=Form1.Color;
C.Pen.Color:=Form1.Color;
C.Ellipse(x1,y1,x1+r,y1+r);
x1:=x1+dx;
y1:=y1-dy;
if (x1+r>xmax)and (y1-1>0) then
begin
Number:=3;
exit;
end;
if (x1+r>xmax)and (y1-1<0) then
begin
Number:=2;
exit;
end;
if (x1+r<xmax)and (y1-1<0) then
begin
Number:=0;
exit;
end;
C.Brush.Color:=Col;
C.Ellipse(x1,y1,x1+r,y1+r)
end;
procedure ball.XMYM (c:Tcanvas);
begin
C.Brush.Color:=Form1.Color;
C.Pen.Color:=Form1.Color;
C.Ellipse(x1,y1,x1+r,y1+r);
x1:=x1-dx;
y1:=y1-dy;
if (x1-1<0)and (y1-1<0) then
begin
Number:=0;
exit;
end;
if (x1-1>0)and (y1-1<0) then
begin
Number:=2;
exit;
end;
if (x1-1<0)and (y1-1>0) then
begin
Number:=1;
exit;
end;
C.Brush.Color:=Col;
C.Ellipse(x1,y1,x1+r,y1+r)
end;
procedure ball.XMYP (c:Tcanvas);
begin
C.Brush.Color:=Form1.Color;
C.Pen.Color:=Form1.Color;
C.Ellipse(x1,y1,x1+r,y1+r);
x1:=x1-dx;
y1:=y1+dy;
if (x1-1>0)and (y1+r>ymax) then
begin
Number:=3;
exit;
end;
if (x1-1<0)and (y1+r>ymax) then
begin
Number:=1;
exit;
end;
if (x1-1<0)and (y1+r<ymax) then
begin
Number:=0;
exit;
end;
C.Brush.Color:=Col;
C.Ellipse(x1,y1,x1+r,y1+r)
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
Xmax:=Form1.Width;
Ymax:=Form1.Height;
for i:=1 to Nmax do
a[i]:=ball.Create;
Timer1.Interval:=1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
VAR
i:integer;
begin
for i:=1 to Nmax do
begin
case a[i].Number of
0:a[i].XPYP(Form1.Canvas);
1:a[i].XPYM(Form1.Canvas);
2:a[i].XMYP(Form1.Canvas);
3:a[i].XMYM(Form1.Canvas);
end;
end;
end;
Procedure TShape;
begin
end;
end. |