From: bwilliam@iat.holonet.net (Bill Williams)
Subject: Re: How do you draw a circle/oval?
Organization: HoloNet National Internet Access BBS: 510-704-1058/modem
Date: Sat, 12 Dec 1992 04:34:04 GMT
Re: Request for filled oval graphics primitive.....


/*=********************************************************************=*/
 
 
/*=********************************************************************=*/
#define INTEGER_32 long int
 
static void Draw_Filled_Ellipse_Primitive(INTEGER_32 start_X
, INTEGER_32 start_Y
                        ,INTEGER_32 axis_A, INTEGER_32 axis_B
                        , PixPatHandle current_Pattern)
{
register INTEGER_32     active_X, active_Y;
register INTEGER_32     axis_A_Squared, axis_B_Squared,
axis_A_Squared_Times_2;
register INTEGER_32     axis_B_Squared_Times_2, derivitive_X,
derivitive_Y, dd;
 
/* END VAR */
   /*=--------------------------------------------------------------------=*/
   /*   Uses dual differential high efficiency technique    */
   /*=--------------------------------------------------------------------=*/
 
   active_X = axis_A;
   active_Y = 0;
   axis_A_Squared = axis_A*axis_A;
   axis_B_Squared = axis_B*axis_B;
   axis_A_Squared_Times_2 = axis_A_Squared + axis_A_Squared;
   axis_B_Squared_Times_2 = axis_B_Squared + axis_B_Squared;
   derivitive_X = axis_B_Squared_Times_2*axis_A;
   derivitive_Y = 0L;
   dd = (axis_B_Squared / 4L) - (axis_B_Squared * axis_A) + axis_A_Squared;
   
   /*=--------------------------------------------------------------------=*/
   /*   Step along Y axis    */
   /*=--------------------------------------------------------------------=*/
   while ( derivitive_X > derivitive_Y ) {
      Draw_Patterned_Eastward_Line_Subprimitive(
               (start_X - active_X)
               , (start_Y - active_Y)
               , (active_X << 1) +1);
 
      Draw_Patterned_Eastward_Line_Subprimitive(
              (start_X - active_X)
              ,(start_Y + active_Y)
              , (active_X << 1) +1);
 
      active_Y +=1;
      derivitive_Y += axis_A_Squared_Times_2;
      if (dd <= 0L )
         dd  += (derivitive_Y + axis_A_Squared);
      else {
         derivitive_X -= axis_B_Squared_Times_2;
         active_X -= 1L;
         dd += (derivitive_Y + axis_A_Squared - derivitive_X );
      }
   } /* while ( derivitive_X > derivitive_Y ) */
   
   /*=--------------------------------------------------------------------=*/
   /*   Step along X axis    */
   /*=--------------------------------------------------------------------=*/
   
   dd += ( ( ((3L *(axis_B_Squared-axis_A_Squared)) / 2L) 
             - ( derivitive_X + derivitive_Y ) ) / 2L);
   
   while ( active_X > 0L ) {
      Draw_Patterned_Eastward_Line_Subprimitive(
          (start_X - active_X),(start_Y - active_Y), (active_X << 1) +1);
 
      Draw_Patterned_Eastward_Line_Subprimitive(
         (start_X - active_X),(start_Y + active_Y), (active_X << 1) +1);
 
      active_X -=1;
      derivitive_X -= axis_B_Squared_Times_2;
      
      if (dd > 0L )
         dd  += (axis_B_Squared - derivitive_X);
      else {
         derivitive_Y += axis_A_Squared_Times_2;
         active_Y += 1L;
         dd += (derivitive_Y + axis_B_Squared - derivitive_X );
      }
   } /* while ( active_X > 0L ) */
 
   while (active_Y <= axis_B) {
 
      Draw_Patterned_Eastward_Line_Subprimitive(start_X
         ,(start_Y + active_Y)
          , 1L); /* actually only one pixel */
 
      Draw_Patterned_Eastward_Line_Subprimitive(start_X
                ,(start_Y - active_Y)
                , 1L);  /* actually only one pixel */
 
      active_Y += 1L;
   }     
} /* Draw_Filled_Ellipse_Primitive */
/*=********************************************************************=*/
 
 
/*=********************************************************************=*/
 
 
I Guarantee this puppy is FAAAAST. I designed it from various sources.
 
(Draw_Patterned_Eastward_Line_Subprimitive should be written as fast as
you can make it.... or just make it a LineTo.)


Enjoy.

Bill Williams