home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / FSGFX.ZIP / G_LINE.C < prev    next >
C/C++ Source or Header  |  1990-03-06  |  856b  |  57 lines

  1. /* g_line.c */
  2. /* draws a graphic line */
  3.  
  4. #include "mygraph.h"
  5.  
  6. int g_line(int startx, int starty, int endx, int endy)
  7. {
  8.     int spot;
  9.     unsigned char uchar;
  10.  
  11.     register int t, distance;
  12.     int xerr=0, yerr=0, delta_x, delta_y;
  13.     int incx, incy;
  14.  
  15.     delta_x=endx-startx;
  16.     delta_y=endy-starty;
  17.  
  18.     if(delta_x>0) 
  19.         incx=1;
  20.     else if(delta_x==0) 
  21.         incx = 0;
  22.     else incx = -1;
  23.  
  24.     if (delta_y>0) 
  25.         incy=1;
  26.     else if(delta_y == 0) 
  27.         incy = 0;
  28.     else 
  29.         incy = -1;
  30.  
  31.     delta_x=abs(delta_x);
  32.     delta_y=abs(delta_y);
  33.  
  34.     if(delta_x>delta_y)
  35.         distance=delta_x;
  36.     else 
  37.         distance = delta_y;
  38.  
  39.     for(t=0; t<=distance+1; t++)
  40.     {
  41.         g_macrodot(startx,starty);
  42.         xerr+=delta_x;
  43.         yerr+=delta_y;
  44.         if(xerr>distance) 
  45.         {
  46.             xerr-=distance;
  47.             startx+=incx;
  48.         }
  49.         if(yerr>distance)
  50.         {
  51.             yerr -= distance;
  52.             starty += incy;
  53.         }
  54.     }
  55. }
  56.  
  57.