unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    PaintBox1: TPaintBox;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{$J+}
procedure TForm1.Timer1Timer(Sender: TObject);
const x:integer=6;
      y:integer=6;
      krokx:integer=6;
      kroky:integer=6;
begin
    with PaintBox1.Canvas do
    begin
      //czyszczenie prostokąta
      Brush.Color:=clWhite;
      Rectangle(0,0,200,200);
     //obliczenie współrzędnych
      x:=x+krokx;
      y:=y+kroky;
     //rysowanie koła w kwadracie o boku
     // równym 6 pikseli
     Brush.Color:=clBlue;
     Ellipse(x-6, y-6, x+6, y+6);
     if (x>Paintbox1.Width-6) then
     begin
       krokx:=6+Random(5);
       krokx:=-krokx;
     end;
     if (y>Paintbox1.Height-6) then
     begin
        kroky:=6+Random(5);
        kroky:=-kroky;
     end;
     if (x<=6) then krokx:=-krokx;
     if (y<=6) then kroky:=-kroky;
   end;  //with
end;

end.
