home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
C-ASM_VI.ARJ
/
PROGC.ZIP
/
PROGC086.C
< prev
next >
Wrap
Text File
|
1988-04-10
|
2KB
|
56 lines
/************************************************************************/
/* Drawing line with brute force algorithm */
/************************************************************************/
slow_line(x0, y0, x1, y1, color)
int x0, y0, x1, y1, color;
{
int x, y;
/*--- Draw degenerate line (pixel) */
if (x0 == x1 && y0 == y1) /* Draw a single pixel */
pixel_write(x0, y0, color);
/*--- Draw lines with dx > dy */
else if (abs(x1 - x0) >= abs(y1 - y0))
{ /* Swap end point */
if (x1 < x0)
{
x = x1;
y = y1;
x1 = x0;
y1 = y0;
x0 = x;
y0 = y;
}
for (x = x0; x <= x1; x++) /* Loop over x coord */
{ /* Compute y using x */
y = y0 + ((x - x0)*(long)(y1 - y0))/(x1 - x0);
pixel_write(x,y,color); /* Draw next point */
}
}
/*--- Draw lines with dy > dx */
else
{
if (y1 < y0) /* Swap end points */
{
x = x1;
y = y1;
x1 = x0;
y1 = y0;
x0 = x;
y0 = y;
}
for (y = y0; y <= y1; y++) /* Loop over y coord */
{ /* Compute x using y */
x = x0 + ((y - y0)*(long)(x1 - x0))/(y1 - y0);
pixel_write(x,y,color); /* Draw next point */
}
}
}