Program Task; Uses GraphABC; Const b = 4; r = 20 ; d: Array [1..4, 1..2] of Integer = ((1, 0), (0, 1), (-1, 0), (0, -1)); xs: Array [1..b] of Integer = (r + r Div 2, WindowWidth - (r + r Div 2), WindowWidth - (r + r Div 2), r + r Div 2); ys: Array [1..b] of Integer = (r + r Div 2, r + r Div 2, WindowHeight - (r + r Div 2), WindowHeight - (r + r Div 2)); Var x, y, dir: Array [1..b] of Integer; i, j: Integer; Begin LockDrawing; For i := 1 To b Do Begin x[i] := xs[i]; y[i] := ys[i]; dir[i] := i; End; While True Do Begin Window.Clear; For i := 1 To b Do Circle(x[i], y[i], r); For i := 1 To b Do Begin x[i] := x[i] + d[dir[i], 1]; y[i] := y[i] + d[dir[i], 2]; End; For i := 1 To b Do For j := 1 To b Do If (x[i] = xs[j]) And (y[i] = ys[j]) Then If dir[i] < b Then dir[i] := dir[i] + 1 Else dir[i] := 1; Redraw; End; End.
Answers & Comments
Verified answer
Program Task;Uses GraphABC;
Const b = 4; r = 20 ;
d: Array [1..4, 1..2] of Integer = ((1, 0), (0, 1), (-1, 0), (0, -1));
xs: Array [1..b] of Integer = (r + r Div 2, WindowWidth - (r + r Div 2), WindowWidth - (r + r Div 2), r + r Div 2);
ys: Array [1..b] of Integer = (r + r Div 2, r + r Div 2, WindowHeight - (r + r Div 2), WindowHeight - (r + r Div 2));
Var x, y, dir: Array [1..b] of Integer;
i, j: Integer;
Begin
LockDrawing;
For i := 1 To b Do
Begin
x[i] := xs[i];
y[i] := ys[i];
dir[i] := i;
End;
While True Do
Begin
Window.Clear;
For i := 1 To b Do
Circle(x[i], y[i], r);
For i := 1 To b Do
Begin
x[i] := x[i] + d[dir[i], 1];
y[i] := y[i] + d[dir[i], 2];
End;
For i := 1 To b Do
For j := 1 To b Do
If (x[i] = xs[j]) And (y[i] = ys[j]) Then
If dir[i] < b Then
dir[i] := dir[i] + 1
Else
dir[i] := 1;
Redraw;
End;
End.