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 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 FillRect(ClipRect); Ellipse(cx-r,cy-r,cx+r,cy+r); 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; 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); 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. |