home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / m / m242 / 2.ddi / VER2FUNC.ZIP / GRDASH.C < prev    next >
Encoding:
Text File  |  1989-10-16  |  1.9 KB  |  89 lines

  1. /* function to draw a dash line */
  2. grdash(c1,r1,c2,r2,color)
  3. int c1; /* column coordinate of first point */
  4. int r1; /* row coordinate of first point */
  5. int c2; /* column coordinate of second point */
  6. int r2; /* row coordinate of second point */
  7. int color; /* foreground color of line */
  8. {
  9. int dr; /* delta r */
  10. int dc; /* delta c */
  11. int rem; /* remainder of slope */
  12. int r; /* row coordinate to write out */
  13. int c; /* column coordinate to write out */
  14. int i; /* counter of # of points written out */
  15. int j; /* temp counter of incrementing remainder */
  16. int ir; /* increment value of row */
  17. int ic; /* increment value of column */
  18.  
  19.  
  20. /* get delta r and c */
  21. dr = ((r1-r2)<0?-(r1-r2):(r1-r2));
  22. dc = ((c1-c2)<0?-(c1-c2):(c1-c2));
  23. /* check that we aren't writing out just one point */
  24. if((dr == 0)&&(dc == 0))
  25.   {
  26.   dot(c1,r1,color);
  27.   return(1);
  28.   }
  29. /* which way does the slope go? */
  30. if(dr > dc) goto vertical;
  31. r = r1;
  32. c = c1;
  33. if(c1 > c2) ic = -1;
  34.   else ic = 1;
  35. if(r1 > r2) ir = -1;
  36.   else ir = 1;
  37. /* get slopes remainder */
  38. rem = dr % dc;
  39. /* write out start point */
  40. dot(c1,r1,color);
  41. /* check for diagonal */
  42. if(dc == dr)
  43.   {
  44.   j = 1;
  45.   dc = 0;
  46.   }
  47.   else j = dc / 2;
  48. /* start loop for line slopes > 1 */
  49. for(i = 1; ; ++i)
  50.   {
  51.   /* are we done ? */
  52.   if((r == r2)&&(c == c2)) { return(i); }
  53.   j = j + rem;
  54.   if(j > dc)
  55.     {
  56.     r = r + ir;
  57.     j = j - dc;
  58.     }
  59.   c = c + ic;
  60.   if((i % 4) != 0) dot(c,r,color);
  61.   }
  62. vertical:
  63. r = r1;
  64. c = c1;
  65. if(c1 > c2) ic = -1;
  66.   else ic = 1;
  67. if(r1 > r2) ir = -1;
  68.   else ir = 1;
  69. /* get slopes remainder */
  70. rem = dc % dr;
  71. /* write out start point */
  72. dot(c1,r1,color);
  73. j = dr / 2;
  74. /* start loop for line slopes < or = 1 */
  75. for(i = 1; ; ++i)
  76.   {
  77.   /* are we done ? */
  78.   if((r == r2)&&(c == c2)) { return(i); }
  79.   j = j + rem;
  80.   if(j > dr)
  81.     {
  82.     c = c + ic;
  83.     j = j - dr;
  84.     }
  85.   r = r + ir;
  86.   if((i % 4) != 0) dot(c,r,color);
  87.   }
  88. }
  89.