home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 7 / 7_1.c next >
Encoding:
Text File  |  1988-08-11  |  910 b   |  43 lines

  1. /* Listing 7-1 */
  2.  
  3. Ellipse( xc, yc, a0, b0 )        /* using equation of ellipse */
  4. int    xc,yc;            /* center of ellipse */
  5. int    a0,b0;            /* major and minor axes */
  6. {
  7.  
  8.     double    x = 0;
  9.     double    y = b0;
  10.     double    Bsquared = (double)b0 * (double)b0;
  11.     double    Asquared = (double)a0 * (double)a0;
  12.     double    sqrt();
  13.  
  14.  
  15.     do                /* do while dy/dx >= -1 */
  16.     {
  17.       y = sqrt( Bsquared - ((Bsquared/Asquared) * x*x) );
  18.       Set4Pixels( (int)x, (int)y, xc, yc, PixelValue );
  19.       ++x;
  20.     }
  21.     while ( (x <= a0) && (Bsquared*x < Asquared*y) );
  22.  
  23.  
  24.     while (y >= 0)            /* do while dy/dx < -1 */
  25.     {
  26.       x = sqrt( Asquared - ((Asquared/Bsquared) * y*y) );
  27.       Set4Pixels( (int)x, (int)y, xc, yc, PixelValue );
  28.       --y;
  29.     }    
  30. }
  31.  
  32.  
  33. Set4Pixels( x, y, xc, yc, n )    /* set pixels in 4 quadrants by symmetry */
  34. int    x,y;
  35. int    xc,yc;
  36. int    n;
  37. {
  38.     SPFunc(xc+x,yc+y,n);
  39.     SPFunc(xc-x,yc+y,n);
  40.     SPFunc(xc+x,yc-y,n);
  41.     SPFunc(xc-x,yc-y,n);
  42. }
  43.