Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi uhr in delphi--> wie die zeiger? (https://www.delphipraxis.net/19010-uhr-delphi-wie-die-zeiger.html)

KingofWerlte 29. Mär 2004 16:22

Re: uhr in delphi--> wie die zeiger?
 
würde aber auch anders gehn ohne die procedur berechne_xy

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
VAR winkel: Real;
    x, y, x1, y1, r, i: Integer;
    hour, min, sec, msec: Word;

begin
Form1.Caption := DateTimeToStr(Now);

        (*alte Grafik löschen*)
        Refresh;

        (*Einpssen des Kreises in das Fenster*)
         if Width <= Height
                then r := Width div 3 
                else r := Height div 3;


        (*Umwandlung in einzelne Integer-Werte*)
        DecodeTime(Now, hour, min, sec, msec);

        (*Sekundenzeiger*)
        winkel := sec * (((2 * pi) / 60)) - pi / 2;

        x := Trunc(Cos(winkel)* r);
        y := Trunc(Sin(winkel)* r);

        x := x + (Width div 2);
        y := y + (Height div 2);

        Canvas.Moveto(Width div 2, Height div 2);
        Canvas.LineTo(x, y);

        (*Minutenzeiger*)
        winkel := min * (((2 * pi) / 60)) - pi / 2;

        x := Trunc(Cos(winkel)* r);
        y := Trunc(Sin(winkel)* r);

        x := x + (Width div 2);
        y := y + (Height div 2);

        Canvas.Moveto(Width div 2, Height div 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) - 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) - 1);
        Canvas.LineTo(x, y);

        (*Stundenzeiger*)
        if hour > 12 then hour := hour -12;
        winkel := (hour * (2 * pi) / 12) + (min * (2 * pi) / 720) - pi / 2;

        x := Trunc(Cos(winkel)* r * 0.61);
        y := Trunc(Sin(winkel)* r * 0.61);

        x := x + (Width div 2);
        y := y + (Height div 2);

        Canvas.Moveto(Width div 2, Height div 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) - 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) - 1);
        Canvas.LineTo(x , y);
        Canvas.Moveto((Width div 2) + 2, (Height div 2) + 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 2, (Height div 2) - 2);
        Canvas.LineTo(x , y);
        Canvas.Moveto((Width div 2 - 2), (Height div 2) + 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 2), (Height div 2) - 2);
        Canvas.LineTo(x , y);

        (*Mittelpunkt*)
        Canvas.Ellipse((Width div 2)-4, (Height div 2)-4,(Width div 2)+ 4,(Height div 2)+ 4);

        (*Ziffernstriche*)
         i := 0;
         FOR i := 0 TO 11 DO
         begin
         winkel := i * (((2 * pi) / 12)) - pi / 2;

         x := Trunc(Cos(winkel)* 1.1*r);
         x1 := Trunc(Cos(winkel)* r);
         y := Trunc(Sin(winkel)* 1.1*r);
         y1 := Trunc(Sin(winkel)* r);

         x := x + (Width div 2);
         x1 := x1 + (Width div 2);
         y := y + (Height div 2);
         y1 := y1 + (Height div 2);
        Canvas.Moveto(x, y);
        Canvas.LineTo(x1, y1);
         end;

        (*Minutenpunkte*)
         i := 0;
         FOR i := 0 TO 59 DO
         begin
         winkel := i * (((2 * pi) / 60)) - pi / 2;

         x := Trunc(Cos(winkel)* 1.1*r);
         y := Trunc(Sin(winkel)* 1.1*r);

         x := x + (Width div 2);
         y := y + (Height div 2);
          Canvas.Pixels[x, y] := clRed;
         Canvas.Ellipse(x-2, y-2,x+2,y+2);
         end;


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := True;
end;

end.

Lillebrohr 29. Mär 2004 16:28

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

scrapt schrieb:

Zitat:

ich kenn mein buch in und auswendig
AutorOfBook := scrapt; ????

XeRo 29. Mär 2004 16:43

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

Zitat von Lillebrohr
Hi,

scrapt schrieb:

Zitat:

ich kenn mein buch in und auswendig
AutorOfBook := scrapt; ????

:mrgreen:

so...nachdem ich jetzt genug wuelltext hab werd ich mal alle austesten und dann auch versuchen selbst einen zu schreiben...

sCrAPt 29. Mär 2004 17:15

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

Zitat von Lillebrohr
Hi,

scrapt schrieb:

Zitat:

ich kenn mein buch in und auswendig
AutorOfBook := scrapt; ????

1. Ich heiß Robert, nicht Thomas ;)
2. Ab bisle zu jung um ein solches Buch rauszubringen :gruebel:
3. Ich beherrsche die Rechtschreibung genau so wenig wie meine Lampe...

^^ raise exception.create('''sCrAPt'' ist ein unzulässiger Autorname für das Buch');

@KingofWerlte: Meinet wegen kannste es auch in ASM schreiben ;)

:angle:, sCrAPt

XeRo 29. Mär 2004 18:39

Re: uhr in delphi--> wie die zeiger?
 
Ich will euch ja nicht zu nahe treten,aber wenn dass ein admin ließt, dann heißt es wieder: Offtopic :wink:

KingofWerlte 29. Mär 2004 19:20

Re: uhr in delphi--> wie die zeiger?
 
@sCrAPt rofl :mrgreen:

Mr_Anderson 23. Nov 2004 16:37

Re: uhr in delphi--> wie die zeiger?
 
Ich habe im internet auch noch einen Code für eine Klasse gefunden, jedoch sagt mit die klasse TRect nichts. Welchen Wert erwartet man wenn man eine Variable die Klasse TRect zuweist?

Anfgefügt habe ich den quellcode
//Edit:
Hab nun einen Tipp von einem "DPUser" erhalten :P
also dass ich einfach
Delphi-Quellcode:
kor.Top := 100;
kor.Left:= 200;
kor.Right:=100;
kor.Bottom:=100;
so eine TRect Variable aussehen kann, jedoch stürzt das Programm mit einer zugriffsverletzung ab:
Delphi-Quellcode:
test.Create(kor,Form1);
MfG
Delphi-Quellcode:
uses Forms,   {TForm}
     Windows,
     Messages,
     SysUtils,
     Variants,
     Classes,
     Controls,
     Dialogs,
     ExtCtrls,
     math,
     Graphics; {TCanvas, TColor}

type TClock = class (TObject)
  private
    FPicture: TPicture;
    FBrush,FPen : TColor;
    FBack,FClock,FImage: TImage;
    FTimer: TTimer;
    procedure Circle;
    procedure FOnTimer(Sender: TObject);
    procedure SetBrush(AValue: TColor);
    procedure SetPen(AValue: TColor);
    procedure SetPicture(AValue: TPicture);
  public
    constructor Create(const ARect: TRect; const AParent: TWinControl);
    destructor Destroy; override;
  published
    property BrushColor: TColor read FBrush write SetBrush;
    property PenColor: TColor read FPen write SetPen;
    property Picture: TPicture read FPicture write SetPicture;
  end; //TClock

implementation

constructor TClock.Create(const ARect: TRect; const AParent: TWinControl);
begin
  inherited Create;
  FPen := clBlack;
  FBrush := clWhite;
  FPicture := TPicture.Create;
  FBack := TImage.Create(AParent);
  FClock := TImage.Create(AParent);
  FImage := TImage.Create(AParent);
  with FBack do
  begin
    Parent := AParent;
    Left := ARect.Left;
    Top := ARect.Top;
    Width := ARect.Right - Left;
    if Width < 50 then
      Width := 50;
    Height := ARect.Bottom - Top;
    if Height < 50 then
      Height := 50;
  end;
  with FClock do
  begin
    Parent := AParent;
    Transparent := TRUE;
    Left := FBack.Left;
    Top := FBack.Top;
    Width := FBack.Width;
    Height := FBack.Height;
    Circle;
  end;
  with FImage do
  begin
    Transparent := TRUE;
    Parent := AParent;
    Left := FBack.Left;
    Top := FBack.Top;
    Width := FBack.Width;
    Height := FBack.Height;
    Canvas.Pen.Width := (Width + Height) div 100;
  end;
  FTimer := TTimer.Create(AParent);
  with FTimer do
  begin
    Interval := 1000;
    OnTimer := FOnTimer;
    Enabled := TRUE;
  end;
end; //TClock.Create

procedure TClock.Circle;
begin
  with FClock do
    with Canvas do
    begin
      Pen.Width := (Width + Height) div 100;
      Pen.Color := Parent.Brush.Color;
      Brush.Color := Parent.Brush.Color;
      Font.Style := Font.Style + [fsBold];
      Font.Size := (Width + Height) div 30;
      Font.Color := FPen;
      Rectangle(Rect(Left, Top, Left + Width, Top + Height));
      Pen.Color := FPen;
      if (FBack.Picture.Graphic = nil) or
        (FBack.Picture.Graphic.Empty) then
        Brush.Color := FBrush;
      Ellipse(Rect(Left, Top, Left + Width, Top + Height));
      TextOut((Width - TextWidth('12')) div 2, Pen.Width + 2, '12');
      TextOut((Width - TextWidth('6')) div 2, Height - TextHeight('6') - Pen.Width, '6');
      TextOut(Left + 2 + Pen.Width, (Height - TextHeight('9')) div 2, '9');
      TextOut(Width - TextWidth('3') - 2 - Pen.Width, (Height - TextHeight('3')) div 2, '3');
    end;
end; //TClock.Circle

procedure TClock.FOnTimer(Sender: TObject);
var
  Default: Integer;
  Hour,
  Min,
  Sec,
  MSec: Word;
begin
  DecodeTime(Now, Hour, Min, Sec, MSec);
  Sec := Sec * 6;
  Min := Min * 6;
  Hour := Hour * 30;
  with FImage do
  begin
    with Canvas do
    begin
      if FPen <> clWhite then
        CopyMode := cmWhiteness
      else
        CopyMode := cmBlackness;
      CopyRect(FImage.BoundsRect, Canvas, FImage.BoundsRect);
      Pen.Color := FPen;
      MoveTo(Width div 2, Height div 2);
      LineTo(Width div 2 + Trunc(Sin(DegToRad(Sec)) * (Width div 2 - Width div 8)), Height div 2 + Trunc(Cos(DegToRad(Sec)) * - (Height div 2 - Height div 8)));
      MoveTo(Width div 2, Height div 2);
      Default := Pen.Width;
      Pen.Width := Pen.Width + 1;
      LineTo(Width div 2 + Trunc(Sin(DegToRad(Min)) * (Width div 2 - Width div 8)), Height div 2 + Trunc(Cos(DegToRad(Min)) * - (Height div 2 - Height div 8)));
      MoveTo(Width div 2, Height div 2);
      Pen.Width := Pen.Width + 1;
      LineTo(Width div 2 + Trunc(Sin(DegToRad(Hour)) * (Width div 3)), Height div 2 + Trunc(Cos(DegToRad(Hour)) * - (Height div 3)));
      Pen.Width := Default;
    end;
  end;
end; //TClock.FOnTimer

procedure TClock.SetBrush(AValue: TColor);
begin
  if FBrush <> AValue then
  begin
    FBrush := AValue;
    Circle;
    FOnTimer(FTimer);
  end;
end; //TClock.SetBrush

procedure TClock.SetPen(AValue: TColor);
begin

  if FPen <> AValue then
  begin
    FPen := AValue;
    Circle;
    FOnTimer(FTimer);
  end;
end; //TClock.SetPen

procedure TClock.SetPicture(AValue: TPicture);
begin
  FPicture.Assign(AValue);
  with FBack do
  begin
    Width := FImage.Width;
    Height := FImage.Height;
    Picture.Assign(FPicture);
    Stretch := TRUE;
    Circle;
    FOnTimer(FTimer);
  end;
end; //TClock.SetPicture

destructor TClock.Destroy;
begin
  FImage.Free;
  FPicture.Free;
  FBack.Free;
  FClock.Free;
  FTimer.Free;
  inherited Destroy;
end; //TClock.Destroy

arbu man 23. Nov 2004 17:14

Re: uhr in delphi--> wie die zeiger?
 
Schau dir mal JEDI an da ist eine richtige Uhr.

Hansa 23. Nov 2004 17:50

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

Zitat von Mr_Anderson
...jedoch sagt mit die klasse TRect nichts. Welchen Wert erwartet man wenn man eine Variable die Klasse TRect zuweist?

Also, ich will ja nichts sagen. 8) Aber es liegt auf der Hand, daß die Delphi-Hilfe das weiß. Und "Rect" sieht doch in etwa schon wie "Rechteck" aus, oder ? Selbst wenn man die Bedeutung vom engl. "rectangle" nicht weiß. :zwinker:

Muetze1 23. Nov 2004 22:11

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

1. TRect ist nur ein Record und keine Klasse (zumindest in der alten Delphi Version die ich benutze - und ich weiss, im BCB ist es eine struct mit Methoden).
2. Du kannst ein Rechteck anstatt einzelnd die Werte zu füllen das ganze unter Benutzung der Rect() Funktion in einer Zeile füllen:
Delphi-Quellcode:
  MyRect := Rect(0, 0, 10, 10);
3. Wenn du damit die Klasse anlegen wolltest (instanziieren), dann ist das der Fehler:
Delphi-Quellcode:
test.Create(kor,Form1);
Versuchs mal lieber so:
Delphi-Quellcode:
 test := TClock.Create(kor, Form1);
4. Wenn du schon auf fremde Implementationen stehst, hier und hier noch zwei andere Komponenten.

MfG
Muetze1


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:39 Uhr.
Seite 2 von 3     12 3      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz