Einzelnen Beitrag anzeigen

christopher85

Registriert seit: 30. Jun 2011
6 Beiträge
 
#15

AW: Polygon drehen

  Alt 1. Jul 2011, 11:54
Hi! Also hier mal der Fertige Quelltext zum Programm: dürfte so laufen. man sollte aber bevor man unterschiedliche winkel ausprobiert immer wieder neu zeichnen weil die variablendeklaration sich in "drehen" überschneidet!vor dem freien verwenden für belege immer wieder n stoßgebet zu meinem dank hinterlassen. dank an das delphiforum


Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Label2: TLabel;
    SpinEdit1: TSpinEdit;
    procedure Button3Click(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation
var p,q,u,v,y,x,n,i:integer;
xp,yp:array[1..100]of integer;
w:extended;


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if n>1 then
  begin
    image1.Canvas.LineTo(xp[1],yp[1]);


  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
image1.Canvas.brush.Style:=bssolid;
image1.Canvas.Pen.Color:=clwhite;
image1.Canvas.Rectangle(0,0,image1.Width,image1.Height);
image1.Canvas.Pen.Color:=clblack;
n:=0

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;


procedure TForm1.Button4Click(Sender: TObject);
var i:integer;
begin
w:=spinedit1.value;
w:=w*Pi/180;
for n:=1 to n do
  begin
    u:=trunc((xp[n]-xp[1])*cos(w)+(yp[n]-yp[1])*sin(w))+xp[1];
    v:=trunc(-(xp[n]-xp[1])*sin(w)+(yp[n]-yp[1])*cos(w))+yp[1];
    image1.Canvas.Pixels[u,v]:=clgreen;
    image1.Canvas.Pen.Color:=clgreen;
    image1.Canvas.Ellipse(u-6,v-6,u+6,v+6);
    xp[n]:=u;
    yp[n]:=v;

  end;
 image1.Canvas.moveto(xp[1],yp[1]);
  for i := 2 to n-1 do

 image1.Canvas.lineto(xp[i],yp[i]);
           image1.Canvas.lineto(xp[1],yp[1]);
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button=mbleft then
    begin
      n:=n+1;
      xp[n]:=x;
      yp[n]:=y;
      image1.Canvas.Rectangle(x-3,y-3,x+3,y+3);
      if n=1 then image1.Canvas.MoveTo(x,y);
      end;
      begin



      image1.Canvas.LineTo(xp[n],yp[n]);
        end;
     if button=mbright then
      begin
        image1.canvas.lineto(xp[1],yp[1]);
      end;
end;

end.
  Mit Zitat antworten Zitat