Autor Beitrag
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 29.03.07 15:41 
(Demoprogramm unten)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    FLastWinkel: Extended;
    FWinkel: Extended;
    procedure DrawWheel;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses math;

const
 cx = 100;
 cy = 100;
 r = 100;

procedure TForm1.DrawWheel;
const
  N = 8;
var
  tx, ty, I: Integer;
  S: String;
begin
  with Image1.Canvas do
  begin
   // Zeichenfläche löschen
   FillRect(ClipRect);
   // Drehknopf zeichnen
   Ellipse(cx-r,cy-r,cx+r,cy+r);
   // Kleine Kreise zeichnen
   for I := 0 to N-1 do
   begin
    tx := round(cos(FWinkel+I/N*2*pi)*(r-10)+cx);
    ty := round(sin(FWinkel+I/N*2*pi)*(r-10)+cy);
    Ellipse(tx-5,ty-5,tx+5,ty+5);
   end;
   // Beschriftung einfügen
   S := Format('%.1f Umdrehungen',[FWinkel/2/pi]);
   TextOut(cx-TextWidth(S) div 2,cy-TextHeight(S) div 2,S);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DrawWheel;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
   FLastWinkel := ArcTan2(Y-cy,X-cx);
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  CurrentWinkel, Delta: Extended;
begin
  if ssLeft in Shift then
  begin
   CurrentWinkel := ArcTan2(Y-cy,X-cx);
   // Berechnung der Änderung des Winkels
   Delta := CurrentWinkel-FLastWinkel;
   if Delta<-pi then
    Delta := Delta + 2*pi else
   if Delta>=pi then
    Delta := Delta - 2*pi;
   FWinkel := FWinkel + Delta;
   DrawWheel;
   FLastWinkel := CurrentWinkel;
  end;
end;

end.


ausblenden dfm
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
object Form1: TForm1
  Caption = 'Form1'
  ClientHeight = 216
  ClientWidth = 216
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OnCreate = FormCreate
  TextHeight = 13
  object Image1: TImage
    Left = 8
    Top = 8
    Width = 200
    Height = 200
    OnMouseDown = Image1MouseDown
    OnMouseMove = Image1MouseMove
  end
end
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von delfiphan am Do 29.03.07 17:21, insgesamt 2-mal bearbeitet
axellang Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Do 29.03.07 16:24 
Zitat:

@Sinspin

- Setz einfach keine Grenze, so das die Werte utopische Größen erreichen können.

Wie gesagt das wollte ich vermeiden.

@delfiphan

Aber hallo! Das ist ja ziemlich geil!

Der erste Ansatz (CurrentValue := MyWheel.Position; LastValue := CurrentValue;) hat mich schon in die richtige Laufbahn geschossen.
Genau das war es.

Vielen Dank für euere schnelle und kompetente Hilfe. Ich werde den Thread als vollends gelöst markieren.


Alexander