unit Uhren;
interface
uses Math, Graphics, Sysutils;
type TKoordinaten=record
X,Y: Integer;
end;
type TUhren=class(TObject)
private
uhX,uhY, uRadius : Integer;
function Koor(Winkel, Laenge: Integer):TKoordinaten;
procedure Minutenzeiger(Can : TCanvas; Farbe: TColor);
procedure Stundenzeiger(Can : TCanvas; Farbe: TColor);
public
procedure Zeitanzeigen(Can: TCanvas; Uhr, Rahmen, Minuten, Stunden: TColor);
constructor Erzeuge(Can: TCanvas; X,Y, Radius: Integer; Uhr, Rahmen, Minuten, Stunden: TColor);
destructor Vernichte(Can: TCanvas);
end;
implementation
constructor TUhren.Erzeuge;
begin
inherited Create;
uhX:=X;
uhY:=Y;
uRadius:=Radius;
end;
destructor TUhren.Vernichte;
begin
inherited Destroy;
Can.Pen.Color:= clWhite;
Can.Brush.Color:= clWhite;
Can.Ellipse(uhx-uRadius,uhy-uRadius,uhx+uRadius,uhy+uRadius);
end;
function TUhren.Koor;
var X,Y: Integer;
begin
X:= Round(sin(Winkel)*Laenge);
Y:= Round(sqrt(sqr(Laenge)-sqr(x)));
case Winkel of
0..90: begin
Koor.X:=uhx+X;
Koor.Y:=uhy+Y;
end;
91..180: begin
Koor.X:=uhx+X;
Koor.Y:=uhy-Y;
end;
181..270: begin
Koor.X:=uhx-X;
Koor.Y:=uhy-Y;
end;
271..359: begin
Koor.X:=uhx-X;
Koor.Y:=uhy+Y;
end;
end;
end;
procedure TUhren.Minutenzeiger;
var Temp: String;
Mins: Integer;
Ziel: TKoordinaten;
begin
Temp:=TimeToStr(Time);
Mins:= StrToInt(Temp[4]+Temp[5]);
Ziel:=Koor((6*Mins),trunc(uRadius*(5/6)));
Can.Pen.Color:=Farbe;
Can.MoveTo(uhx,uhy);
Can.LineTo(Ziel.X,Ziel.Y);
end;
procedure TUhren.Stundenzeiger;
var Temp: String;
Mins: Integer;
Ziel: TKoordinaten;
begin
Temp:=TimeToStr(Time);
Mins:= StrToInt(Temp[1]+Temp[2]);
Ziel:=Koor((30*Mins),Round(uRadius*(0.5)));
Can.Pen.Color:=Farbe;
Can.MoveTo(uhx,uhy);
Can.LineTo(Ziel.X,Ziel.Y);
end;
procedure TUhren.Zeitanzeigen;
begin
Can.Pen.Color:=Rahmen;
Can.Brush.Color:=Uhr;
Can.Ellipse(uhx-uRadius,uhy-uRadius,uhx+uRadius,uhy+uRadius);
Minutenzeiger(Can, Minuten);
Stundenzeiger(Can, Stunden);
end;
end.