KODE DFP HEAD Algoritma DDA | Programming And Networking

YM

Link

IKLAN ADSENSE BAWAH SIDEBAR (250X250)

Algoritma DDA

output :


Source :

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls, Grids, Buttons;

type

{ TForm1 }

TForm1 = class(TForm)
btntutup: TBitBtn;
btnproses: TBitBtn;
Image1: TImage;
rgagar: TRadioGroup;
StringGrid1: TStringGrid;
procedure btnprosesClick(Sender: TObject);
procedure btntutupClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DDA(xa, ya, xb, yb : Integer);
procedure Image1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
{ public declarations }
end;

var
Form1: TForm1;
X1,X2,Y1,Y2:Integer;
tergambar:Boolean;
implementation

{ TForm1 }

procedure TForm1.DDA(xa, ya, xb, yb: Integer);
var
dx, dy, step, k: Integer;
xincrement, Yincrement, x, y:Real;
begin
xa:=10;
ya:=10;
xb:=17;
yb:=16;
dx:=xb-xa;
dy:=yb-ya;
x:=round(xa);
y:=round(ya);
if (abs(dx)>abs(dy)) then
step := (abs(dx))
else
step := (abs(dy));
Xincrement:=(dx/step);
Yincrement:=(dy/step);
Image1.Canvas.Pixels[trunc(x),trunc(y)]:=clBlack;
for k:=0 to step do
begin
x+=xincrement;
y+=Yincrement;
StringGrid1.RowCount:=StringGrid1.RowCount+1;
StringGrid1.Cells[0,stringGrid1.RowCount-1]:=IntToStr(k);
StringGrid1.Cells[1,stringGrid1.RowCount-1]:=FloatToStr(x);
StringGrid1.Cells[2,stringGrid1.RowCount-1]:=FloatToStr(y);
StringGrid1.Cells[3,stringGrid1.RowCount-1]:=FloatToStr(round(x));
StringGrid1.Cells[4,stringGrid1.RowCount-1]:=FloatToStr(round(y));
Image1.Canvas.Pixels[trunc(x),trunc(y)]:=clBlack;
end;
end;

procedure TForm1.Image1Click(Sender: TObject);
begin

end;


procedure TForm1.btntutupClick(Sender: TObject);
begin
Close();
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:='K';
StringGrid1.Cells[1,0]:='X';
StringGrid1.Cells[2,0]:='Y';
StringGrid1.Cells[3,0]:='X(Bulat)';
StringGrid1.Cells[4,0]:='Y(Bulat)';
StringGrid1.Cells[1,1]:='10';
StringGrid1.Cells[2,1]:='10';
StringGrid1.Cells[3,1]:='10';
StringGrid1.Cells[4,1]:='10';
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
tergambar:=true;
X1:=X;
Y1:=Y;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
tergambar:=False;
btnprosesClick(Sender);
X2:=X;
Y2:=Y;

if rgagar.ItemIndex=0 then
DDA(X1,Y1,X2,Y2);
begin
Image1.Canvas.MoveTo(X1,Y1);
Image1.Canvas.LineTo(X2,Y2);
end;
end;

procedure TForm1.btnprosesClick(Sender: TObject);
begin
tergambar:=False;
Image1.Canvas.Rectangle(0,0,Image1.Width, Image1.Height);
end;

initialization
{$I unit1.lrs}

end.