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

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