![]() |
Re: Canvas Zeichnung drehen
Die funktion ist doch relativ selbsterklärend:
Delphi-Quellcode:
position ist der Punkt den du drehen willst.
function RotateCCW(position,axis: TPoint; alpha: single): TPoint;
axis ist der Punkt um den gedreht werden soll alpha ist der Drehwinkel um die Figur zu drehen musst du einfach für jeden Punkt die funktion aufrufen und den Rückgabewert in deiner zeichenprocedure verwenden. Um die figur langsam zu drehen musst du alpha z:B. in einem timer erhöhen und dann jeweils das Mänchen neuzeichnen. mfg, Ratte |
Re: Canvas Zeichnung drehen
mhmm.... ok doch wie wende ich jetzt diese schöne funktion auf alle punkte meines männchens an?
kann man die innerhalb einer procedure aufrufen oder wie? |
Re: Canvas Zeichnung drehen
naja mit der ellipse wirds schwerer, aber die Linien gehen so:
Delphi-Quellcode:
a: single;
[...] procedure TMann2.zeichnen; var axis: TPoint; p : TPoint; begin axis := Point(xpos + 8, ypos + 50); [...] 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); [...] |
Re: Canvas Zeichnung drehen
ouh man hab versucht das bei mir einzubidnen aber ich bekomme es echt nicht zum laufen..ich bin echt total am verzweifeln wäre vllt. einer so lieb und könnte das für mich amchen.. scheint ja nicht all zu viel arbeit zu sein....
wäre echt super.... :( |
Re: Canvas Zeichnung drehen
weil ich heut meinen guten Tag hab ;)
Delphi-Quellcode:
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. aber jetzt bitte keine Fragen mehr. ich hab feierabend :) |
Re: Canvas Zeichnung drehen
gut jetz verstehe ich von dem code zwar eigentlich gar nichts aber ok^^
ich mach mich gleich mla damit schlau ;) |
Re: Canvas Zeichnung drehen
na großer zauberer was macht die kunst?
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:53 Uhr. |
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