Einzelnen Beitrag anzeigen

sCrAPt
(Gast)

n/a Beiträge
 
#10

Re: uhr in delphi--> wie die zeiger?

  Alt 29. Mär 2004, 17:19
hiho

Habs ein bischen total überarbeitet...

pbUhr war bei mir eine (T)Paintbox (größe is egal)

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
  procedure Berechne_xy(Winkel: real; Art: real; var xi, yi: integer);
  // Empfohlende Art-Werte:
  // Stunde: 0.48
  // Minute: 0.38
  // Sekunde: 0.28
  var
    x, y: real;
  begin
    Winkel := Winkel - pi / 2;
    x := Cos(Winkel);
    y := Sin(Winkel);

    x := x * (pbUhr.Width * art);
    y := y * (pbUhr.Height * art);
    x := x + (pbUhr.Width div 2);
    y := y + (pbUhr.Height div 2);

    xi := trunc(x);
    yi := trunc(y);
  end;
const
  stundenzeigercl = clred;
  minutenzeigercl = clblue;
  sekundenzeigercl = cllime;
  uhrkreiscl = $000080FF;
  mittelpunktcl = clblack;
  umkreisstrichecl = clyellow;
var
  std, min, sek, msek: word;
  x, y, winkel: integer;
begin
  DecodeTime(now, std, min, sek, msek);
  if std > 12 then dec(std, 12);

  with pbUhr do
  begin
    Refresh;

    Canvas.Pen.Color := uhrkreiscl;
    Canvas.Ellipse(0, 0, pbUhr.Width, pbUhr.Height);

    // Stunden
    Berechne_xy(((2 * pi) / 12) * std, 0.48, x, y);
    canvas.Pen.Color := stundenzeigercl;
    canvas.MoveTo(width div 2 - 2, height div 2);
    canvas.LineTo(x, y);

    // Minuten
    Berechne_xy(((2 * pi) / 60) * min, 0.38, x, y);
    canvas.Pen.Color := minutenzeigercl;
    canvas.MoveTo(width div 2 - 2, height div 2);
    canvas.LineTo(x, y);

    // Sekunden
    Berechne_xy(((2 * pi) / 60) * sek, 0.28, x, y);
    canvas.Pen.Color := sekundenzeigercl;
    canvas.MoveTo(width div 2 - 2, height div 2);
    canvas.LineTo(x, y);

    // Design
    Canvas.Brush.Color := mittelpunktcl;
    Canvas.Pen.Color := mittelpunktcl;
    Canvas.Ellipse(pbUhr.Width div 2 - 4, pbUhr.Height div 2 - 4, pbUhr.Width div 2 + 2, pbUhr.Height div 2 + 2);

    Canvas.Pen.Color := umkreisstrichecl;
    Canvas.MoveTo(width div 2, 1);
    Canvas.LineTo(width div 2, 5);

    Canvas.MoveTo(width - 5, height div 2);
    Canvas.LineTo(width - 1, height div 2);

    Canvas.MoveTo(width div 2, height - 5);
    Canvas.LineTo(width div 2, height + 1);

    Canvas.MoveTo(5, height div 2);
    Canvas.LineTo(1, height div 2);
  end
end;
^^ Viel Spaß damit

, sCrAPt
  Mit Zitat antworten Zitat