unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Math;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type TMann2 =
class
xpos,ypos : integer;
a : single;
axis: TPoint;
constructor create(Mx,My :integer);
procedure zeichnen(Winkel: single = 0);
end;
var
Form1: TForm1;
Mann2: TMann2;
implementation
{$R *.dfm}
function RotateCCW(position,axis: TPoint; alpha: single): TPoint;
var relative: TPoint;
begin
relative := Point(position.x - axis.x,position.y - axis.y);
result.x := axis.x + round(relative.x* cos(alpha) + relative.y*sin(alpha));
result.y := axis.y + round(relative.x*-sin(alpha) + relative.y*cos(alpha));
end;
procedure TMann2.zeichnen(Winkel: single = 0);
var
p: TPoint;
begin
a := winkel;
form1.Repaint;
p := RotateCCW(Point(xpos,ypos+10),axis,a);
Form1.Canvas.Ellipse(p.x-10,p.y-10,p.x+10,p.y+10);
p := RotateCCW(Point(xpos,ypos+20),axis,a);
Form1.Canvas.Moveto(p.x,p.y);
p := RotateCCW(Point(xpos,ypos+50),axis,a);
Form1.Canvas.LineTo(p.x,p.y);
p := RotateCCW(Point(xpos+10,ypos+70),axis,a);
Form1.Canvas.LineTo(p.x,p.y);
p := RotateCCW(Point(xpos,ypos+50),axis,a);
Form1.Canvas.Moveto(p.x,p.y);
p := RotateCCW(Point(xpos-10,ypos+70),axis,a);
Form1.Canvas.LineTo(p.x,p.y);
p := RotateCCW(Point(xpos,ypos+25),axis,a);
Form1.Canvas.Moveto(p.x,p.y);
p := RotateCCW(Point(xpos-5,ypos+45),axis,a);
Form1.Canvas.LineTo(p.x,p.y);
p := RotateCCW(Point(xpos,ypos+25),axis,a);
Form1.Canvas.Moveto(p.x,p.y);
p := RotateCCW(Point(xpos+5,ypos+45),axis,a);
Form1.Canvas.LineTo(p.x,p.y);
end;
constructor TMann2.create (Mx,My:integer);
begin
inherited Create;
// macht man nunmal so ;)
xpos:=Mx;
ypos:=My;
a := 0;
axis := Point(xpos -10, ypos + 70);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Mann2.Zeichnen;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
while mann2.a < pi/2
do
begin
mann2.a := mann2.a + 0.05;
mann2.zeichnen(mann2.a);
sleep(50);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Mann2:=TMann2.create(400,300);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
while mann2.a > 0
do
begin
mann2.a := mann2.a - 0.05;
mann2.zeichnen(mann2.a);
sleep(50);
end;
end;
end.