AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Canvas Zeichnung drehen
Thema durchsuchen
Ansicht
Themen-Optionen

Canvas Zeichnung drehen

Ein Thema von Gnaaman · begonnen am 1. Jun 2006 · letzter Beitrag vom 2. Jun 2006
Antwort Antwort
Seite 2 von 2     12   
Ratte

Registriert seit: 12. Dez 2003
Ort: Erfurt
345 Beiträge
 
Delphi 2005 Personal
 
#11

Re: Canvas Zeichnung drehen

  Alt 1. Jun 2006, 19:14
Die funktion ist doch relativ selbsterklärend:
function RotateCCW(position,axis: TPoint; alpha: single): TPoint; position ist der Punkt den du drehen willst.
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
Schiffsratte der U.S.S. Delphipraxis, Laderaum 4538
BUSH:= TTerminator.create;
  Mit Zitat antworten Zitat
Gnaaman

Registriert seit: 31. Mai 2006
14 Beiträge
 
#12

Re: Canvas Zeichnung drehen

  Alt 1. Jun 2006, 19:30
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?
  Mit Zitat antworten Zitat
hboy

Registriert seit: 16. Jan 2004
364 Beiträge
 
#13

Re: Canvas Zeichnung drehen

  Alt 1. Jun 2006, 19:41
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);
[...]
Power is nothing without TControl
  Mit Zitat antworten Zitat
Gnaaman

Registriert seit: 31. Mai 2006
14 Beiträge
 
#14

Re: Canvas Zeichnung drehen

  Alt 1. Jun 2006, 19:56
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....
  Mit Zitat antworten Zitat
hboy

Registriert seit: 16. Jan 2004
364 Beiträge
 
#15

Re: Canvas Zeichnung drehen

  Alt 1. Jun 2006, 20:20
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
Power is nothing without TControl
  Mit Zitat antworten Zitat
Gnaaman

Registriert seit: 31. Mai 2006
14 Beiträge
 
#16

Re: Canvas Zeichnung drehen

  Alt 1. Jun 2006, 20:47
gut jetz verstehe ich von dem code zwar eigentlich gar nichts aber ok^^

ich mach mich gleich mla damit schlau
  Mit Zitat antworten Zitat
hboy

Registriert seit: 16. Jan 2004
364 Beiträge
 
#17

Re: Canvas Zeichnung drehen

  Alt 2. Jun 2006, 15:44
na großer zauberer was macht die kunst?
Power is nothing without TControl
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:34 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz