You are on page 1of 6

TUGAS

BRESENHAM & MIDPOINT

Oleh :

NAMA : ARI WARDANA


NIM : DBC 116 042

JURUSAN TEKNIK INFORMATIKA


FAKULTAS TEKNIK
UNIVERSITAS PALANGKA RAYA
2018
A. DDA (Digital Differential Analyzer)
Coding
procedure TForm1.Button1Click(Sender: TObject);
var dx,dy,fstep,f,x1,x2,y1,y2:integer;
deltax,deltay,x,y:real;
begin
x1:=strtoint(edit1.Text);
y1:=strtoint(edit2.Text);
x2:=strtoint(edit3.Text);
y2:=strtoint(edit4.Text);

dx:=(x2-x1);
dy:=(y2-y1);
if (abs(dx)>abs(dy)) then fstep := abs(dx) else fstep := abs(dy);

deltax:= dx/fstep;
deltay:= dy/fstep;
x:=x1;y:=y1;
canvas.Pixels[trunc(x),trunc(y)] := clblue;

for f := 0 to fstep -1 do
begin
x := x + deltax;
y := y + deltay;
canvas.Pixels[trunc(x),trunc(y)]:= clblue;
end;
end;
A. Bresenham
Coding
procedure TForm1.Button1Click(Sender: TObject);
var p,dx,dy,xend,f,x,y,xa,xb,ya,yb: integer;
begin
xa:= strtoint(edit1.Text);
xb:= strtoint(edit3.Text);
ya:= strtoint(edit2.Text);
yb:= strtoint(edit4.Text);
dx:=abs(xa-xb);
dy:= abs (ya-yb);
p:=(2*dy)-dx;

if (xa>xb) then
begin
x:=xb;
y:=yb;
xend:=xa;
end else
begin
x:=xa;
y:=ya;
xend:=xb;
end;
canvas.Pixels[x,y]:= clred;

for f := 0 to xend do
begin
x:=x+1;
if (p<0) then
p:=p+(2*dy)
else
begin
y:=y+1;
p:=p+(2*(dy-dx));
end;
canvas.Pixels[x,y]:=clred;
end;
end;
end.
B. Midpoint Lingkaran
Coding
procedure TForm1.Button1Click(Sender: TObject);
var x, y, p, xc, yc, radius : integer;
begin
x:=0;
radius:= strtoint(edit3.Text);
yc:= strtoint(edit2.Text);
xc:= strtoint(edit1.Text);
y:=radius;
p:=1-radius;
while(x<y)do
begin
canvas.Pixels[xc+x,yc+y]:=clred;
canvas.Pixels[xc+x,yc-y]:=clred;
canvas.Pixels[xc-x,yc+y]:=clred;
canvas.Pixels[xc-x,yc-y]:=clred;
canvas.Pixels[xc+y,yc+x]:=clred;
canvas.Pixels[xc+y,yc-x]:=clred;
canvas.Pixels[xc-y,yc+x]:=clred;
canvas.Pixels[xc-y,yc-x]:=clred;
if(p<0)then
begin
x:=x+1;
p:=p+2*X+1;
end
else
begin
x:=x+1;
y:=y-1;
p:=p+2*(x-y)+1;
end;
end;
end;
end.

You might also like