home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-ASM_VI.ARJ / PROGC.ZIP / PROGC088.C < prev    next >
Text File  |  1988-04-10  |  3KB  |  66 lines

  1.  
  2. /************************************************************************/
  3. /* Draw a line with a pattern using the 'slow' algorithm                */
  4. /************************************************************************/
  5.  
  6. slow_pattern_line(x0, y0, x1, y1, color,pattern)
  7. int     x0, y0, x1, y1, color, pattern;
  8.         {
  9.         int     x, y;
  10.         static int mask[16] = {
  11.                                 0x8000,0x4000,0x2000,0x1000,
  12.                                 0x0800,0x0400,0x0200,0x0100,
  13.                                 0x0080,0x0040,0x0020,0x0010,
  14.                                 0x0008,0x0004,0x0002,0x0001};
  15.  
  16.         /*--- Draw degenerate line (pixel)                              */
  17.  
  18.         if (x0 == x1 && y0 == y1)               /* Draw a single pixel  */
  19.                 {
  20.                 if (mask[x0 & 15] & pattern)
  21.                         pixel_write(x0, y0, color);
  22.                 }
  23.  
  24.         /*--- Draw lines with dx > dy                                   */
  25.  
  26.         else if (abs(x1 - x0) >= abs(y1 - y0))
  27.                 {                               /* Swap end points      */
  28.                 if (x1 < x0)
  29.                         {
  30.                         x = x1;
  31.                         y = y1;
  32.                         x1 = x0;
  33.                         y1 = y0;
  34.                         x0 = x;
  35.                         y0 = y;
  36.                         }
  37.                 for (x = x0; x <= x1; x++)      /* Loop over x coord    */
  38.                     {                           /* Compute y using x    */
  39.                 y = y0 + ((x - x0)*(long)(y1 - y0))/(x1 - x0);
  40.                 if (mask[x & 15] & pattern)
  41.                         pixel_write(x,y,color); /* Draw next point      */
  42.                     }
  43.                 }
  44.  
  45.         /*--- Draw lines with dy > dx                                   */
  46.  
  47.         else
  48.                 {
  49.                 if (y1 < y0)                    /* Swap end points      */
  50.                         {
  51.                         x = x1;
  52.                         y = y1;
  53.                         x1 = x0;
  54.                         y1 = y0;
  55.                         x0 = x;
  56.                         y0 = y;
  57.                         }
  58.                 for (y = y0; y <= y1; y++)      /* Loop over y coord    */
  59.                     {                           /* Compute x using y    */
  60.                     x = x0 + ((y - y0)*(long)(x1 - x0))/(y1 - y0);
  61.                     if (mask[y & 15] & pattern)
  62.                         pixel_write(x,y,color);  /* Draw next point      */
  63.                     }
  64.                 }
  65.         }
  66.