Line Drawing withough BGI Help
Hi all! I just had a question about drawing lines directly to video.
I have succesfully written a horiz, and vert line procedures in
assembly and am now trying to make line drawing procedure that can
handle sloped lines. This is what I came up with and was wondering if
anyone had suggestions on ways of optimising it..
procedure Line( x1,y1,x2,y2 : integer;col : byte);
var Xdist,Ydist,
x,y,inc : integer;
begin
Xdist := abs(x2-x1);
Ydist := abs(y2-y1);
if xdist = 0 then
HorizLine(x1,y1,y2,col)
else if ydist = 0 then
VertLine(x1,y1,x2,col)
else
begin
if x1 > x2 then
begin
x := x1;
x1 := x2;
x2 := x;
end;
if y1 > y2 then
begin
y := y1;
y1 := y2;
y2 := y;
end;
if xdist >= ydist then
begin
inc := round(xdist / ydist);
x := x1;
for y := y1 to y2 do
begin
for x := x to x+inc do
putpixel(x,y,col);
end;
end
else
begin
inc := round(ydist / xdist);
y := y1;
for x := x1 to x2 do
begin
for y := y to y+inc do
putpixel(x,y,col);
end;
end;
end;
end;
=Brent Hostetler ============================
================== www.kaiwan.com/~brenth ===
+===========================================+