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 >
Text File  |  1988-04-10  |  2KB  |  56 lines

  1.  
  2. /************************************************************************/
  3. /* Drawing line with brute force algorithm                              */
  4. /************************************************************************/
  5.  
  6. slow_line(x0, y0, x1, y1, color)
  7. int     x0, y0, x1, y1, color;
  8.         {
  9.         int     x, y;
  10.  
  11.         /*--- Draw degenerate line (pixel)                              */
  12.  
  13.         if (x0 == x1 && y0 == y1)               /* Draw a single pixel  */
  14.                 pixel_write(x0, y0, color);
  15.  
  16.         /*--- Draw lines with dx > dy                                   */
  17.  
  18.         else if (abs(x1 - x0) >= abs(y1 - y0))
  19.                 {                               /* Swap end point       */
  20.                 if (x1 < x0)
  21.                         {
  22.                         x = x1;
  23.                         y = y1;
  24.                         x1 = x0;
  25.                         y1 = y0;
  26.                         x0 = x;
  27.                         y0 = y;
  28.                         }
  29.                 for (x = x0; x <= x1; x++)      /* Loop over x coord    */
  30.                     {                           /* Compute y using x    */
  31.                     y = y0 + ((x - x0)*(long)(y1 - y0))/(x1 - x0);
  32.                     pixel_write(x,y,color);     /* Draw next point      */
  33.                     }
  34.                 }
  35.  
  36.         /*--- Draw lines with dy > dx                                   */
  37.  
  38.         else
  39.                 {
  40.                 if (y1 < y0)                    /* Swap end points      */
  41.                         {
  42.                         x = x1;
  43.                         y = y1;
  44.                         x1 = x0;
  45.                         y1 = y0;
  46.                         x0 = x;
  47.                         y0 = y;
  48.                         }
  49.                 for (y = y0; y <= y1; y++)      /* Loop over y coord    */
  50.                     {                           /* Compute x using y    */
  51.                     x = x0 + ((y - y0)*(long)(x1 - x0))/(y1 - y0);
  52.                     pixel_write(x,y,color);     /* Draw next point      */
  53.                     }
  54.                 }
  55.         }
  56.