home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG035.ARC / GRAFLINE.C < prev    next >
Text File  |  1979-12-31  |  2KB  |  106 lines

  1.  
  2. /********************************************************/
  3. /*                            */
  4. /*    Line-Plotting Routines for MX-80 Graphics    */
  5. /*                            */
  6. /*    Don Brittain        3 January 1983        */
  7. /*                            */
  8. /********************************************************/
  9.  
  10. #define NO 0
  11. #define YES 1
  12. extern int horsize, versize, flag;
  13. extern int pixplot(), unpixplot();
  14.  
  15.  
  16. lineplot(x,y,h,v)    /* plots segment from (x,y) to (h,v) */
  17.  
  18. int x,y,h,v;
  19.  
  20. {
  21.     if((x==h)&&(y==v)) noline(x,y);
  22.     else
  23.     if(abs(y-v)<abs(h-x))
  24.         if(x<h)
  25.         horline(x,y,h,v);
  26.         else
  27.         horline(h,v,x,y);
  28.     else
  29.         if(y<v)
  30.         vertline(x,y,h,v);
  31.         else
  32.         vertline(h,v,x,y);
  33. }
  34.  
  35.  
  36. noline(x,y)    /* treats case where (x,y) = (h,v) */
  37.  
  38. int x,y;
  39.  
  40. {
  41.     if(flag)
  42.     pixplot(x,y);
  43.     else
  44.     unpixplot(x,y);
  45. }
  46.  
  47.  
  48. abs(x)        /* absolute-value function for integers */
  49.  
  50. int x;
  51.  
  52. {
  53.     if(x>0)
  54.     return(x);
  55.     else
  56.     return(-x);
  57. }
  58.  
  59.  
  60. horline(x,y,h,v)     /* plots line having  abs(slope) <= 1  */
  61.             /* assumes x < h   */
  62. int x,y,h,v;
  63.  
  64. {
  65.     register i;
  66.     long k;
  67.     short l;
  68.     
  69.     if(flag)
  70.     for(i=x; i<=h; i++)    {
  71.         k=v;
  72.         k=(k-y)*(i-x);
  73.         l=k/(h-x)+y;
  74.         pixplot(i,l);    }
  75.     else
  76.     for(i=x; i<=h; i++)    {
  77.         k=v;
  78.         k=(k-y)*(i-x);
  79.         l=k/(h-x)+y;
  80.         unpixplot(i,l);    }
  81. }
  82.  
  83. vertline(x,y,h,v)    /* plots line having abs(slope) >= 1 */
  84.             /* assumes y < v */
  85. int x,y,h,v;
  86.  
  87. {
  88.     register i;
  89.     long k;
  90.     short l;
  91.     
  92.     if(flag)
  93.     for(i=y; i<=v; i++)    {
  94.         k=h;
  95.         k=(k-x)*(i-y);
  96.         l=k/(v-y)+x;
  97.         pixplot(l,i);    }
  98.     else
  99.     for(i=y; i<=v; i++)    {
  100.         k=h;
  101.         k=(k-x)*(i-y);
  102.         l=k/(v-y)+x;
  103.         unpixplot(l,i);    }
  104.     }
  105.     
  106.