home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / func / lblcs / crt_ln32.c < prev    next >
Encoding:
Text File  |  1985-04-05  |  3.8 KB  |  149 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. /******************************************************************
  7.  *
  8.  * name        crt_line320 - plot lines w/ fast 320x200 point routine
  9.  *
  10.  * synopsis    crt_line320(row1, col2, row2, col2, color)
  11.  *        int row1,col2,row2,col2,color;
  12.  *
  13.  * description    This routine uses a simple octantal DDA to plot 
  14.  *        lines on your 320 x 200 COLOR graphics screen.  The
  15.  *        screen needs to be set to graphics mode, of course...
  16.  *
  17.  * notes    This routine is still written in 'C'.  It is faster 
  18.  *        than many of the other line draw routines I have seen
  19.  *        around, but still relatively slow compared to assembler.
  20.  *        Next released version of the libraries will have this 
  21.  *        one written in assembler...
  22.  *
  23.  *        Works only in 320x200 color graphics mode!!
  24.  * 
  25.  * bugs        Better be sure that your x and y values are in range
  26.  *        no range checking is done.
  27.  ********************************************************************/
  28.  
  29. crt_line320(startx, starty, endx, endy, color)
  30. int  startx, starty, endx, endy, color;
  31.     {
  32.     int count, deltax, deltay, error, t;
  33.  
  34.  
  35.     if (endx < startx)
  36.         {
  37.         t = startx;             /* fold quadrants 2, 3 to 1, 4  */
  38.         startx = endx;
  39.         endx = t;
  40.         t = starty;
  41.         starty = endy;
  42.         endy = t;
  43.         }
  44.     deltax = endx - startx;
  45.     deltay = endy - starty;
  46.     if (deltay < 0)
  47.         {
  48.         if (-deltay > deltax)   /* octant 7             */
  49.             {
  50.             count = -deltay;
  51.             error = deltay / 2;
  52.             do
  53.                 {
  54. /*              if (flag)
  55.                     pixerase(startx + XOFF, YOFF - starty);
  56.                 else
  57.                     pixplot(startx + XOFF, YOFF - starty);
  58.  
  59. */
  60.         crt_ps32(startx, starty, color);
  61.  
  62.                 starty--;
  63. è                if ((error += deltax) >= 0)
  64.                     {
  65.                     startx++;
  66.                     error += deltay;
  67.                     }
  68.                 }
  69.             while (--count >= 0);
  70.             }
  71.         else                    /* octant 8             */
  72.             {
  73.             count = deltax;
  74.             error = -deltax / 2;
  75.             do
  76.                 {
  77. /*
  78.                 if (flag)
  79.                     pixerase(startx + XOFF, YOFF - starty);
  80.                 else
  81.                     pixplot(startx + XOFF, YOFF - starty);
  82.  
  83. */
  84.  
  85.         crt_ps32(startx, starty, color);
  86.  
  87.  
  88.                 startx++;
  89.                 if ((error -= deltay) >= 0)
  90.                     {
  91.                     starty--;
  92.                     error -= deltax;
  93.                     }
  94.                 }
  95.             while (--count >= 0);
  96.             }
  97.         }
  98.     else if (deltay > deltax)       /* octant 2         */
  99.         {
  100.         count = deltay;
  101.         error = -deltay / 2;
  102.         do
  103.             {
  104. /*
  105.             if (flag)
  106.                 pixerase(startx + XOFF, YOFF - starty);
  107.             else
  108.                 pixplot(startx + XOFF, YOFF - starty);
  109.  
  110. */
  111.         crt_ps32(startx , starty, color);
  112.  
  113.  
  114.             starty++;
  115.             if ((error += deltax) >= 0)
  116.                 {
  117.                 startx++;
  118.                 error -= deltay;
  119.                 }
  120.             }
  121.         while (--count >= 0);
  122.         }
  123. è    else                        /* octant 1             */
  124.         {
  125.         count = deltax;
  126.         error = -deltax/2;
  127.         do
  128.             {
  129.   
  130. /*
  131.           if (flag)
  132.                 pixerase(startx + XOFF, YOFF - starty);
  133.             else
  134.                 pixplot(startx + XOFF, YOFF - starty);
  135. */
  136.         crt_ps32(startx , starty, color);
  137.  
  138.  
  139.             startx++;
  140.             if ((error += deltay) >= 0)
  141.                 {
  142.                 starty++;
  143.                 error -= deltax;
  144.                 }
  145.             }
  146.         while (--count >= 0);
  147.         }
  148.     }
  149.  
  150.  
  151.