0% found this document useful (0 votes)
44 views6 pages

Bresenham & Midpoint Algorithms Code

This document discusses algorithms for drawing lines and circles on a canvas in Pascal. It contains code for the Digital Differential Analyzer (DDA) line drawing algorithm, Bresenham's line drawing algorithm, and the midpoint circle drawing algorithm. The DDA and Bresenham's algorithms draw lines between points specified by the user. The midpoint circle algorithm draws a circle based on a center point and radius specified by the user.

Uploaded by

Ari Wardana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views6 pages

Bresenham & Midpoint Algorithms Code

This document discusses algorithms for drawing lines and circles on a canvas in Pascal. It contains code for the Digital Differential Analyzer (DDA) line drawing algorithm, Bresenham's line drawing algorithm, and the midpoint circle drawing algorithm. The DDA and Bresenham's algorithms draw lines between points specified by the user. The midpoint circle algorithm draws a circle based on a center point and radius specified by the user.

Uploaded by

Ari Wardana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like