this slowpoke moves

Draw Animate Analog Clock

var
  Form1: TForm1;
  coul : TColor;
  dh : TDateTime;
  s, s2 : LongInt;
  xp, yp, R : Integer;
  
//

procedure TForm1.FormResize(Sender: TObject);
begin
  Bevel1.Width := Form1.ClientWidth - 16;
  Bevel1.Height := Form1.ClientHeight - 16 - 65;
  PaintBox1.Width := Form1.ClientWidth - 18;
  PaintBox1.Height := Form1.ClientHeight - 18 - 65;
  Panel1.Width := Form1.ClientWidth - 16;
  Panel2.Width := Form1.ClientWidth - 16;
  Panel1.Top := Form1.ClientHeight - 16 - 48;
  Panel2.Top := Form1.ClientHeight - 16 - 15;
  if PaintBox1.Width <= PaintBox1.Height then R := PaintBox1.Width div 2 - PaintBox1.Width div 10
  else R := PaintBox1.Height div 2 - PaintBox1.Height div 10;
  xp := PaintBox1.Width div 2;
  yp := PaintBox1.Height div 2;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DoubleBuffered := true;
  coul := clLime;
  if PaintBox1.Width <= PaintBox1.Height then R := PaintBox1.Width div 2 - PaintBox1.Width div 10
  else R := PaintBox1.Height div 2 - PaintBox1.Height div 10;
  xp := PaintBox1.Width div 2;
  yp := PaintBox1.Height div 2;
end;

procedure TForm1.ColorClick(Sender: TObject);
begin
  if ColorDialog1.Execute then begin
    coul := ColorDialog1.Color;
    PaintBox1.Repaint;
    Panel1.Font.Color := coul;
    Panel2.Font.Color := coul;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var asec, amin, ahour : Real;
begin
  dh := Now;
  if Panel2.Caption <> DateToStr(dh) then Panel2.Caption := DateToStr(dh);
  //DecodeTime(dh, h, m, s, ms);
  //if (h < 10) then Panel1.Caption := '0' + IntToStr(h) + ':'
  //else Panel1.Caption := IntToStr(h) + ':';
  //if (m < 10) then Panel1.Caption := Panel1.Caption + '0' + IntToStr(m) + ':'
  //else Panel1.Caption := Panel1.Caption + IntToStr(m) + ':';
  //if (s < 10) then Panel1.Caption := Panel1.Caption +'0' + IntToStr(s)
  //else Panel1.Caption := Panel1.Caption + IntToStr(s);
  s := SecondOfTheDay(dh);
  if s <> s2 then begin
  PaintBox1.Repaint;
  if Panel1.Caption <> TimetoStr(dh) then Panel1.Caption := TimetoStr(dh);
  PaintBox1.Canvas.Pen.Color := coul;
  PaintBox1.Canvas.MoveTo(xp, yp);
  asec := s*Pi/30;
  PaintBox1.Canvas.LineTo(xp+round(R*cos(asec-Pi/2)), yp+round(R*sin(asec-Pi/2)));
  PaintBox1.Canvas.MoveTo(xp, yp);
  amin := s*Pi/1800;
  PaintBox1.Canvas.LineTo(xp+round((2*R/3)*cos(amin-Pi/2)), yp+round((2*R/3)*sin(amin-Pi/2)));
  PaintBox1.Canvas.MoveTo(xp, yp);
  ahour := s*Pi/21600;
  PaintBox1.Canvas.LineTo(xp+round((R/3)*cos(ahour-Pi/2)), yp+round((R/3)*sin(ahour-Pi/2)));
  end;
  s2 := s;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
  i : integer;
  a : Real;
  myrect, minir : TRect;
begin
  myrect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
  PaintBox1.Canvas.Brush.Color := clBlack;
  PaintBox1.Canvas.FillRect(myrect);
  for i:= 0 to 11 do begin
    a := i*Pi/6;
    minir := Rect(xp+round(R*cos(a))-2, yp+round(R*sin(a))-2, xp+round(R*cos(a))+2, yp+round(R*sin(a))+2);
    PaintBox1.Canvas.Brush.Color := coul;
    PaintBox1.Canvas.FillRect(minir);
  end;
end;

procedure TForm1.FormConstrainedResize(Sender: TObject; var MinWidth,
  MinHeight, MaxWidth, MaxHeight: Integer);
begin
  MinWidth := 90;
  MinHeight := 170;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate