home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / C128CPM / SGTOOLS17.ARC / VDCELLPI.C < prev   
Encoding:
C/C++ Source or Header  |  1994-06-01  |  1.4 KB  |  74 lines

  1. /*
  2. SG C Tools 1.7
  3.  
  4. (C) 1994 Steve Goldsmith
  5. All Rights Reserved
  6.  
  7. Compiled with HI-TECH C 3.09 (CP/M-80).
  8. */
  9.  
  10. #include <hitech.h>
  11. #include <vdc.h>
  12.  
  13. /*
  14. Draw ellipse in 640 X 480 interlace using digital differential analyzer (DDA)
  15. method.
  16. */
  17.  
  18. void ellipseivdc(int XC, int YC, int A, int B)
  19. {
  20.   long AA = (long) A*A; /* a^2 */
  21.   long BB = (long) B*B; /* b^2 */
  22.   long AA2 = AA << 1;   /* 2(a^2) */
  23.   long BB2 = BB << 1;   /* 2(b^2) */
  24.  
  25.   {
  26.     long X = 0;
  27.     long Y = B;
  28.     long XBB2 = 0;
  29.     long YAA2 = Y*AA2;
  30.     long ErrVal = -Y*AA; /* b^2 x^2 + a^2 y^2 - a^2 b^2 -b^2x */
  31.  
  32.     while (XBB2 <= YAA2) /* draw octant from top to top right */
  33.     {
  34.       setpixivdc(XC+X,YC+Y);
  35.       setpixivdc(XC+X,YC-Y);
  36.       setpixivdc(XC-X,YC+Y);
  37.       setpixivdc(XC-X,YC-Y);
  38.       X += 1;
  39.       XBB2 += BB2;
  40.       ErrVal += XBB2-BB;
  41.       if (ErrVal >= 0)
  42.       {
  43.         Y -= 1;
  44.         YAA2 -= AA2;
  45.         ErrVal -= YAA2;
  46.       }
  47.     }
  48.   }
  49.   {
  50.     long X = A;
  51.     long Y = 0;
  52.     long XBB2 = X*BB2;
  53.     long YAA2 = 0;
  54.     long ErrVal = -X*BB;
  55.  
  56.     while (XBB2 > YAA2)  /* draw octant from right to top right */
  57.     {
  58.       setpixivdc(XC+X,YC+Y);
  59.       setpixivdc(XC+X,YC-Y);
  60.       setpixivdc(XC-X,YC+Y);
  61.       setpixivdc(XC-X,YC-Y);
  62.       Y += 1;
  63.       YAA2 += AA2;
  64.       ErrVal += YAA2-AA;
  65.       if (ErrVal >= 0)
  66.       {
  67.         X -= 1;
  68.         XBB2 -= BB2;
  69.         ErrVal -= XBB2;
  70.       }
  71.     }
  72.   }
  73. }
  74.