Registriert seit: 21. Okt 2003
Ort: Dresden
177 Beiträge
|
Re: uhr in delphi--> wie die zeiger?
27. Mär 2004, 17:26
Wenn du eine richtige Analoguhr proggen willst, dann hilft dir das bestimmt weiter:
Delphi-Quellcode:
procedure TForm1.Berechne_stunde(winkel: Real;
var xi, yi: Integer);
var x,y: Real;
begin
winkel := winkel - pi / 2;
x := Cos(Winkel);
y := Sin(Winkel);
x := x * (Width div 4);
y := y * (Height div 4);
x := x + (Width div 2);
y := y + (Height div 2);
xi := Trunc(x);
yi := Trunc(y);
end;
procedure TForm1.Berechne_xy(winkel: Real;
var xi, yi: Integer);
var x,y: Real;
begin
winkel := winkel - pi / 2;
x := Cos(Winkel);
y := Sin(Winkel);
x := x * (Width div 3);
y := y * (Height div 3);
x := x + (Width div 2);
y := y + (Height div 2);
xi := Trunc(x);
yi := Trunc(y);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var winkel: Integer;
hour, min, sec, msec: Word;
x, y: Integer;
begin
Refresh;
Label1.Caption := DateToStr(Now);
Label2.Caption := TimeToStr(Now);
DecodeTime(Now, hour, min, sec, msec);
//Sekundenzeiger zeichnen
Berechne_xy(((2 * Pi) / 60) * sec, x, y);
Canvas.Pen.Color:=clNavy;
Canvas.Pen.Width := 1;
Canvas.MoveTo(Width div 2, Height div 2);
Canvas.LineTo(x, y);
//Minutenzeiger zeichnen
Berechne_xy(((2 * Pi) / 60) * min, x, y);
Canvas.Pen.Color:=clBlack;
Canvas.Pen.Width := 2;
Canvas.MoveTo(Width div 2, Height div 2);
Canvas.LineTo(x, y);
//Stundenzeiger zeichnen
if hour > 12 then hour := hour - 12;
Berechne_stunde(((2 * Pi) / 12) * hour, x, y);
Canvas.Pen.Color:=clBlack;
Canvas.Pen.Width := 3;
Canvas.MoveTo(Width div 2, Height div 2);
Canvas.LineTo(x, y);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := True; // Damit flackern die Zeiger nicht so ;)
end;
|
|
Zitat
|