TForm5 = class(TForm)
Image1: TImage;
Timer1: TTimer;
....
procedure Image1Paint(Sender: TObject);
Procedure Timer1Timer (Sender : TObject);
.....
private
AHour : Word;
AMin : Word;
ASec : Word;
public
end;
const Deg2Rad = pi/180;
Procedure TForm5.Timer1Timer (Sender : TObject);
var junk : word;
begin
DecodeTime(Now,AHour,AMin,ASec,Junk);
Image1.Invalidate;
end;
// analog clock, image 90 x 90
procedure TForm5.Image1Paint(Sender: TObject);
const ro=20; // Minutenzeiger
centerX=45;
centerY=47;
var x,y,x1,y1,x2,y2 : integer;
h,degH, degMin, degSec, sinus, cosinus : single;
begin
// hours
h := Ahour;
if h >=12 then h := h - 12;
h := h + AMin/60;
degH := h* 30 - 90; // Uhr (Nord) fängt 90° vor Lazarus (Ost) an
math.sincos(degH*Deg2Rad, sinus, cosinus);
x := round (cosinus*ro*0.75)+centerX;
y := round (sinus *ro*0.75) +CenterY;
// minutes
degMin := Amin*6 -90;
math.sincos(degMin*Deg2Rad, sinus, cosinus);
x1 := round (cosinus*ro)+centerX;
y1 := round (sinus*ro)+centerY;
// seconds
degSec := ASec*6 -90;
math.sincos(degSec*Deg2Rad, sinus, cosinus);
x2 := round (cosinus*ro*1.15)+centerX;
y2 := round (sinus*ro*1.15)+centerY;
with Image1.Canvas do
begin
pen.width := 5;
pen.Color := clBlack;
pen.EndCap := pecRound;
line(centerX, centerY,x,y); // hours
line(centerX, centerY,x1,y1); // minutes
pen.width := 1;
brush.Color := clLime;
EllipseC(x,y,3,3); // radium, luminous lime-green, very 60th
EllipseC(x1,y1,3,3);
pen.Color := clRed;
line(centerX, centerY,x2,y2); // seconds
pen.Color := clBlack;
Brush.color := clSilver;
EllipseC (centerX, centerY,3,3);
end;
end;