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 / GRAFCIRC.C < prev    next >
Text File  |  1979-12-31  |  1KB  |  65 lines

  1.  
  2. /********************************************************/
  3. /*                            */
  4. /*    Circle-Plotting Routine for MX-80 Graphics    */
  5. /*                            */
  6. /*    Don Brittain        3 January 1983        */
  7. /*                            */
  8. /********************************************************/
  9.  
  10. #define NO 0
  11. #define YES 1
  12.  
  13. extern int flag;
  14. extern int pixplot(), unpixplot();
  15.  
  16. circle(x,y,r)        /* plots circle with center (x,y) and  */
  17.             /* radius = r */
  18. int x,y,r;
  19.  
  20. {
  21.     register i;
  22.     int end, sqt;
  23.     long li, lr;
  24.     
  25.     lr=r;
  26.     if(flag)
  27.     {
  28.     end=r-r/4;
  29.     for(i=r/4-r; i<=end; i++)    {
  30.         li=i;
  31.         sqt=sqrt(lr*lr-li*li);
  32.         pixplot(x+i,y+sqt);
  33.         pixplot(x+i,y-sqt);
  34.         pixplot(x+sqt,y+i);
  35.         pixplot(x-sqt,y+i);        }
  36.     }
  37.     else
  38.     {
  39.     end=r-r/4;
  40.     for(i=r/4-r; i<=end; i++)    {
  41.         li=i;
  42.         sqt=sqrt(lr*lr-li*li);
  43.         unpixplot(x+i,y+sqt);
  44.         unpixplot(x+i,y-sqt);
  45.         unpixplot(x+sqt,y+i);
  46.         unpixplot(x-sqt,y+i);    }
  47.     }
  48. }
  49.  
  50. sqrt(x)        /* Cluge returning approximate square-root of integers */
  51.  
  52. long x;
  53.  
  54. {
  55.     register i;
  56.     
  57.     if(x<0)    {
  58.     printf("Argument error in SQRT.\n\n");
  59.     return(-1);    }
  60.     for(i=0; i<x; i++)
  61.     if((i*i)>=(x-i/2)) return(i);
  62. }
  63.  
  64.     
  65.