Cara Membuat Garis Menggunakan
Metode Bresenham
Ø Codingnya:
var
//var Garis bresenham//
Form1: TForm1;
x0,y0,x,y,x1,y1,x2,y2,k,e,deltaX,deltaY:integer;
procedure TForm1.FormPaint(Sender: TObject);
var
x,y:integer;
begin
for x:=0 to clientwidth do
canvas.pixels[x,clientheight div 2]:=clblue;
for y:=0 to clientheight do
canvas.pixels[clientwidth div 2,y]:=clblue;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// rumus Garis Bresenham//
x0:=ClientWidth div 2;
y0:=ClientHeight div 2;
x1:=StrToInt(edit1.text);
x2:=StrToInt(edit2.Text);
y1:=StrToInt(edit3.Text);
y2:=StrToInt(edit4.Text);
deltaX:=x2-x1;deltaY:=y2-y1;
e:=2*deltaY-deltaX;
x:=x1;y:=y1;
for k:=1 to deltaX do
begin
// untuk Garis kanan Atas//
canvas.Pixels[x0+x,y0-y]:=clred;
if e>0 then
begin
y:=y+1;
e:=e+2*(deltaY-deltaX);
end
Else e:=e+2*deltaY;
x:=x+1;
end;
end;
Tidak ada komentar:
Posting Komentar