unit Rund3;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TKreis = class
    x, y, Dicke: Integer;
    constructor Create (xx,yy,dd: Integer);
    procedure Erscheinen;
    procedure Bewegen;
    procedure Verschwinden;
    function Flaeche: Single;
    function Umfang: Single;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Kreis: TKreis;

implementation

{$R *.DFM}

constructor TKreis.Create (xx,yy,dd: Integer);
begin
  x := xx; y := yy; Dicke := dd;
end;

procedure TKreis.Erscheinen;
begin
  Form1.Canvas.Ellipse (x, y, x+Dicke, y+Dicke);
end;

procedure TKreis.Bewegen;
var i: Integer; Quelle, Ziel: TRect;
begin
  for i := x-5 to Form1.ClientWidth-Dicke-x-5 do
  begin
    Quelle := Rect(i,   y-5, i+Dicke+7, y+Dicke+5);
    Ziel   := Rect(i+1, y-5, i+Dicke+7, y+Dicke+5);
    Form1.Canvas.CopyRect(Ziel, Form1.Canvas, Quelle);
    sleep (10);
  end;
end;

procedure TKreis.Verschwinden;
begin
  Form1.Refresh;
end;

function TKreis.Flaeche: Single;
begin
  Flaeche := pi*(Dicke/2)*(Dicke/2);
end;

function TKreis.Umfang: Single;
begin
  Umfang := Pi*Dicke;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Kreis := TKreis.Create (30,30,180);
  Canvas.Brush.Color := clWhite;  // ansonsten Grau
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Kreis.Erscheinen;
  Canvas.TextOut (60,100, 'Fläche = '
    + FloatToStrF(Kreis.Flaeche, ffNumber, 8, 2));
  Canvas.TextOut (60,120, 'Umfang = '
    + FloatToStrF(Kreis.Umfang, ffNumber, 8, 2));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Kreis.Bewegen;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Kreis.Verschwinden;
end;

end.
