home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hall of Fame
/
HallofFameCDROM.cdr
/
proglc
/
line.lzh
/
LINE.C
Wrap
Text File
|
1980-01-01
|
2KB
|
63 lines
/* NAME line - draws a line on the crt */
/* SYNOPSIS */
/* line(x, y, color); */
/* int x; X coordinate */
/* int y; Y coordinate */
/* int val; 0..7 */
/* COLORS */ /* ====================================== */
/* 0 = Black 4 = Green */
/* 1 = Blue 5 = Cyan */
/* 2 = Red 6 = Yellow */ /* 3 = Magenta 7 = White */
/* By Rick H. Wesson 09-06-1985 */
/* This procedure uses Bresenham's theory */
line(x1, y1, x2, y2, val)
int x1,
y1,
x2,
y2,
val;
{
int d,
x,
y,
dx,
dy,
incr1,
incr2,
xend;
dx = abs(x2 - x1);
dy = abs(y2 - y1);
d = 2 * dy - dx;
incr1 = 2 * dy;
incr2 = 2 * (dy - dx);
if(x1 > x2){
x = x2;
y = y2;
xend = x1;
}
else{
x = x1;
y = y1;
xend = x2;
}
plot(x, y, val);
while(x < xend){
x++;
if(d < 0)
d += incr1;
else{
y++;
d += incr2;
}
plot(x, y, val);
}
}