Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Bezier yaklaşım eğrileri

unit PolyBezierEgrisi; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; StaticText1: TStaticText; Timer1: TTimer; Label1: TLabel; StaticText2: TStaticText; Label2: TLabel; Button3: TButton; procedure FormCreate(Sender: TObject); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Button1Click(Sender: TObject); procedure cizabicim; procedure Button2Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; i:integer; dizi:Array of Integer; x1,y1,x2,y2,x3,y3,x4,y4:integer; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin form1.Canvas.Brush.Color:=clyellow; Form1.Font.Color:=clBlue; i:=0;//tıklamayı tutacak x1:=0; y1:=0; x2:=0; y2:=0; x3:=0; y3:=0; x4:=0; y4:=0; WindowState:=wsMaximized; end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin i:=i+1;//ilk tıklamayı tutup daha sonra artacak if i=1 then begin x1:=X; y1:=Y; Form1.Canvas.Ellipse(x1+3,y1+3,x1-3,y1-3); Form1.Canvas.TextOut(x1+5,y1+5,'1'); form1.Canvas.MoveTo(x1,y1); end else if i=2 then begin x2:=X; y2:=Y; Form1.Canvas.Ellipse(x2+3,y2+3,x2-3,y2-3); Form1.Canvas.LineTo(x2,y2); Form1.Canvas.TextOut(x2+5,y2+5,'2'); form1.Canvas.MoveTo(x2,y2); // Canvas.PolyBezierTo([Point(x1,y1),Point(x2,y2),Point(x3,y3),Point(x4,y4)]); end else if i=3 then Begin x3:=X; y3:=Y; Form1.Canvas.Ellipse(x3+3,y3+3,x3-3,y3-3); Form1.Canvas.LineTo(x3,y3); Form1.Canvas.TextOut(x3+5,y3+5,'3'); form1.Canvas.MoveTo(x3,y3); // Canvas.PolyBezier([Point(x1,y1),Point(x2,y2),Point(x3,y3),Point(x4,y4)]); end else if i=4 then Begin x4:=X; y4:=Y; Form1.Canvas.Ellipse(x4+3,y4+3,x4-3,y4-3); Form1.Canvas.LineTo(x4,y4); Form1.Canvas.TextOut(x4+5,y4+5,'4'); // Canvas.PolyBezier([Point(x1,y1),Point(x2,y2),Point(x3,y3),Point(x4,y4)]); end; end; procedure TForm1.Button1Click(Sender: TObject); begin if (x1=0) or (y1=0) or (x2=0) or (y2=0) or (x3=0) or (y3=0) or (x4=0) or (y4=0) then Showmessage('Yaklaşım Eğrisi için önce 4 noktayı seçiniz') else cizabicim; Canvas.PolyBezier([Point(x1,y1),Point(x2,y2),Point(x3,y3),Point(x4,y4)]); end; procedure TForm1.cizabicim; begin Canvas.PolyBezier([Point(x1,y1),Point(x2,y2),Point(x3,y3),Point(x4,y4)]); end; procedure TForm1.Button2Click(Sender: TObject); begin Form1.Refresh; i:=0;//tıklama sayısını tutacak x1:=0; y1:=0; x2:=0; y2:=0; x3:=0; y3:=0; x4:=0; y4:=0; end; procedure TForm1.Timer1Timer(Sender: TObject); begin StaticText1.Caption:=Copy(StaticText1.Caption,2,Length(StaticText1.Caption)-1)+StaticText1.Caption[1]; Label1.Caption:=TimeToStr(Time); Label2.Caption:=DateToStr(Date); end; end.