home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_06_06
/
v6n6090a.txt
< prev
next >
Wrap
Text File
|
1989-09-28
|
1KB
|
100 lines
\NLETTER\6.6\CURVES56.PRG Program 6
void line (x1,y1,x2,y2, ci)
int x1, x2, y1, y2, ci;
{
int dx, dy, inc1, inc2, inc3, d, x, y, xend, yend;
dx = abs(x2-x1);
dy = abs(y2-y1);
if (dy<=dx)
{
if (x1>x2)
{
x = x2;
y = y2;
xend = x1;
dy = y1 - y2;
}
else
{
x = x1;
y = y1;
xend = x2;
dy = y2 - y1;
}
d = 2*dy-dx;
inc1 = 2*dy;
inc2 = 2*(dy-dx);
inc3 = 2*(dy+dx);
writepixel (x,y,ci);
while (x<xend)
{
x++;
if (d>=0)
{
if (dy<=0) d+= inc1;
else
{
y++;
d += inc2;
}
}
else
{
if (dy>=0) d+= inc1;
else
{
y --;
d += inc3;
}
}
writepixel (x,y,ci);
}
}
else
{
if (y1>y2)
{
y = y2;
x = x2;
yend = y1
dx = x1 - x2;
}
else
{
y = y1;
x = x1;
tebd = y2;
}
d = 2*dx-dy;
inc1 = 2*dx;
inc2 = 2*(dx - dy);
inc3 = 2*(dx + dy);
writepixel (x,y,ci);
while (y<yend)
{
y++;
if (d>=0)
{
if (dx <= 0) d+= inc1;
else
{
x++;
d += inc2;
}
}
else
{
if (dx >= 0) d + = inc1;
else
{
x --;
d += inc3;
}
}
writepixel (x,y,,ci);
}
}
}