home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / line.lzh / LINE.C
Text File  |  1980-01-01  |  2KB  |  63 lines

  1.  
  2.                 
  3.  
  4. /* NAME  line - draws a line on the crt        */
  5. /* SYNOPSIS                                    */                      
  6. /*       line(x, y, color);                    */                      
  7. /*       int x;         X coordinate           */                      
  8. /*       int y;         Y coordinate           */                      
  9. /*       int val;       0..7                   */                      
  10. /*               COLORS                        */                               /*  ======================================     */                      
  11. /*      0 = Black       4 = Green              */                      
  12. /*      1 = Blue        5 = Cyan               */                      
  13. /*      2 = Red         6 = Yellow             */                               /*      3 = Magenta     7 = White              */                      
  14. /* By Rick H. Wesson 09-06-1985                */
  15. /* This procedure uses Bresenham's theory      */
  16.  
  17.  
  18. line(x1, y1, x2, y2, val)
  19.  int    x1, 
  20.         y1, 
  21.         x2, 
  22.         y2, 
  23.         val;
  24. {
  25.         int     d, 
  26.                 x, 
  27.                 y, 
  28.                 dx, 
  29.                 dy, 
  30.                 incr1, 
  31.                 incr2, 
  32.                 xend;
  33.  
  34.         dx = abs(x2 - x1);
  35.         dy = abs(y2 - y1);
  36.         d = 2 * dy - dx;
  37.         incr1 = 2 * dy;
  38.         incr2 = 2 * (dy - dx);
  39.         if(x1 > x2){
  40.                 x = x2;
  41.                 y = y2;
  42.                 xend = x1;
  43.                }
  44.          else{
  45.                 x = x1;
  46.                 y = y1;
  47.                 xend = x2;
  48.                }
  49.         plot(x, y, val);
  50.         while(x < xend){
  51.                 x++;
  52.                 if(d < 0)
  53.                         d += incr1;
  54.                  else{
  55.                         y++;
  56.                         d += incr2;
  57.                        }
  58.                 plot(x, y, val);
  59.                }
  60. }
  61.  
  62.  
  63.