home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / SGTOOL12.ARC / LIBC128.ARC / VDCLINE.C < prev    next >
C/C++ Source or Header  |  1993-08-10  |  1KB  |  73 lines

  1. /*
  2. SG C Tools 1.2
  3.  
  4. (C) 1993 Steve Goldsmith
  5. All Rights Reserved
  6.  
  7. Compiled with HI-TECH C 3.09 (CP/M-80).
  8. */
  9.  
  10. #include <hitech.h>
  11. #include <vdc.h>
  12.  
  13. /* draw line using modified bresenham's algorithm */
  14.  
  15. void linevdc(int X1, int Y1, int X2, int Y2)
  16. {
  17.   int XInc = 1;
  18.   int YInc = 1;
  19.   int DX, DY, X, Y, C, R;
  20.  
  21.   DX = X2-X1;  /* delta x */
  22.   if(DX < 0)   /* adjust for negative delta */
  23.   {
  24.     XInc = -1;
  25.     DX = -DX;
  26.   }
  27.   DY = Y2-Y1;  /* delta y */
  28.   if(DY < 0)   /* adjust for negative delta */
  29.   {
  30.     YInc = -1;
  31.     DY = -DY;
  32.   }
  33.   else
  34.     if(DY > 0)
  35.       YInc = 1;
  36.     else
  37.       YInc = 0;
  38.  
  39.   X = X1;
  40.   Y = Y1;
  41.   setpixvdc(X,Y); /* set first point */
  42.   if (DX > DY)    /* always draw with positive increment */
  43.   {
  44.     R = DX >> 1;
  45.     for(C = 1; C <= DX; C++)
  46.     {
  47.       X += XInc;
  48.       R += DY;
  49.       if(R >= DX)
  50.       {
  51.         Y += YInc;
  52.         R -= DX;
  53.       }
  54.       setpixvdc(X,Y);
  55.     }
  56.   }
  57.   else
  58.   {
  59.     R = DY >> 1;
  60.     for(C = 1; C <= DY; C++)
  61.     {
  62.       Y += YInc;
  63.       R += DX;
  64.       if(R >= DY)
  65.       {
  66.         X += XInc;
  67.         R -= DY;
  68.       }
  69.       setpixvdc(X,Y);
  70.     }
  71.   }
  72. }
  73.