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([Link]);
y1:=strtoint([Link]);
x2:=strtoint([Link]);
y2:=strtoint([Link]);
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;
[Link][trunc(x),trunc(y)] := clblue;
for f := 0 to fstep -1 do
begin
x := x + deltax;
y := y + deltay;
[Link][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([Link]);
xb:= strtoint([Link]);
ya:= strtoint([Link]);
yb:= strtoint([Link]);
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;
[Link][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;
[Link][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([Link]);
yc:= strtoint([Link]);
xc:= strtoint([Link]);
y:=radius;
p:=1-radius;
while(x<y)do
begin
[Link][xc+x,yc+y]:=clred;
[Link][xc+x,yc-y]:=clred;
[Link][xc-x,yc+y]:=clred;
[Link][xc-x,yc-y]:=clred;
[Link][xc+y,yc+x]:=clred;
[Link][xc+y,yc-x]:=clred;
[Link][xc-y,yc+x]:=clred;
[Link][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.