unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormCreate(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  cx,cy,r:integer;//центер х,у, радиус
  ha,ma,sa:integer;//срелка часов, минут, секунд
  h,m,s,ms:word;//часы, минуты, секунды, милисекунды
  hag,mag,sag:real;//угол часов, минут, секунд

implementation

uses Alarm_;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
if Button1.Caption='Start' then
  begin
   //запуск часов
   DecodeTime(time,h,m,s,ms);
   hag:=(h mod 12)/12*(2*pi);
   mag:=m/60*(2*pi);
   sag:=s/60*(2*pi);
   ArrowDraw(clRed);
   Button1.Caption:='Stop';
   Timer1.Enabled:=true;
  end
  else
   begin
    //остановка часов
    Button1.Caption:='Start';
    Timer1.Enabled:=false;
   end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
cy:=Form1.ClientHeight div 2;
 cx:=cy;
 r:=cx-20;
 ha:=r-30;
 ma:=r-20;
 sa:=r-10;
end;

procedure TForm2.FormPaint(Sender: TObject);
var
 i:integer;
begin
 //прорисовка циферблата
 with Form1.Canvas do
  begin
   //вывод окружности
   Pen.Color:=clBlue;
   Pen.Width:=4;
   Brush.Color:=clWhite;
   Ellipse(20,20,20+2*r,20+2*r);
   Pen.Width:=2;
   //вывод рисок
   for i:=0 to 11 do
    begin
     MoveTo(cx+Round((r-9)*sin(i/6*pi)),cy-Round((r-9)*cos(i/6*pi)));
     LineTo(cx+Round((r)*sin(i/6*pi)),cy-Round((r)*cos(i/6*pi)));
    end;
   //вывод цифр
   Font.Height:=10;
   Font.Color:=clBlack;
   Brush.Color:=Form1.Color;
   TextOut(cx-TextWidth('12') div 2,cy-r-TextHeight('12')-5,'12');
   TextOut(cx+r+5,cy-TextHeight('3'),'3');
   TextOut(cx-TextWidth('6') div 2,cy+r+5,'6');
   TextOut(cx-r-TextWidth('9')-5,cy-TextHeight('9'),'9');
  end; 
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
 //стереть стрелки
 ArrowDraw(clWhite);
 //нарисовать стрелки на новом месте
 DecodeTime(time,h,m,s,ms);
 hag:=(h mod 12)/12*(2*pi);
 mag:=m/60*(2*pi);
 sag:=s/60*(2*pi);
 ArrowDraw(clRed);
end;

procedure TForm2.ArrowDraw(DrawColor: TColor);
begin
 with Form1.Canvas do
  begin
   Pen.Color:=DrawColor;
   MoveTo(cx,cy);
   Pen.Width:=3;
   LineTo(cx+Round(ha*sin(hag)),cy-Round(ha*cos(hag)));
   MoveTo(cx,cy);
   Pen.Width:=2;
   LineTo(cx+Round(ma*sin(mag)),cy-Round(ma*cos(mag)));
   MoveTo(cx,cy);
   Pen.Width:=1;
   LineTo(cx+Round(sa*sin(sag)),cy-Round(sa*cos(sag)));
  end; 
end;


end.
