home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19711 < prev    next >
Encoding:
Text File  |  1992-12-12  |  4.2 KB  |  125 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!spool.mu.edu!agate!iat.holonet.net!bwilliam
  3. From: bwilliam@iat.holonet.net (Bill Williams)
  4. Subject: Re: How do you draw a circle/oval?
  5. Message-ID: <Bz4q0t.2wE@iat.holonet.net>
  6. Organization: HoloNet National Internet Access BBS: 510-704-1058/modem
  7. References: <mxmora-101292153410@css-mac1.sri.com>
  8. Date: Sat, 12 Dec 1992 04:34:04 GMT
  9. Re: Request for filled oval graphics primitive.....
  10. Lines: 113
  11.  
  12.  
  13. /*=********************************************************************=*/
  14.  
  15.  
  16. /*=********************************************************************=*/
  17. #define INTEGER_32 long int
  18.  
  19. static void Draw_Filled_Ellipse_Primitive(INTEGER_32 start_X
  20. , INTEGER_32 start_Y
  21.                         ,INTEGER_32 axis_A, INTEGER_32 axis_B
  22.                         , PixPatHandle current_Pattern)
  23. {
  24. register INTEGER_32     active_X, active_Y;
  25. register INTEGER_32     axis_A_Squared, axis_B_Squared,
  26. axis_A_Squared_Times_2;
  27. register INTEGER_32     axis_B_Squared_Times_2, derivitive_X,
  28. derivitive_Y, dd;
  29.  
  30. /* END VAR */
  31.    /*=--------------------------------------------------------------------=*/
  32.    /*   Uses dual differential high efficiency technique    */
  33.    /*=--------------------------------------------------------------------=*/
  34.  
  35.    active_X = axis_A;
  36.    active_Y = 0;
  37.    axis_A_Squared = axis_A*axis_A;
  38.    axis_B_Squared = axis_B*axis_B;
  39.    axis_A_Squared_Times_2 = axis_A_Squared + axis_A_Squared;
  40.    axis_B_Squared_Times_2 = axis_B_Squared + axis_B_Squared;
  41.    derivitive_X = axis_B_Squared_Times_2*axis_A;
  42.    derivitive_Y = 0L;
  43.    dd = (axis_B_Squared / 4L) - (axis_B_Squared * axis_A) + axis_A_Squared;
  44.    
  45.    /*=--------------------------------------------------------------------=*/
  46.    /*   Step along Y axis    */
  47.    /*=--------------------------------------------------------------------=*/
  48.    while ( derivitive_X > derivitive_Y ) {
  49.       Draw_Patterned_Eastward_Line_Subprimitive(
  50.                (start_X - active_X)
  51.                , (start_Y - active_Y)
  52.                , (active_X << 1) +1);
  53.  
  54.       Draw_Patterned_Eastward_Line_Subprimitive(
  55.               (start_X - active_X)
  56.               ,(start_Y + active_Y)
  57.               , (active_X << 1) +1);
  58.  
  59.       active_Y +=1;
  60.       derivitive_Y += axis_A_Squared_Times_2;
  61.       if (dd <= 0L )
  62.          dd  += (derivitive_Y + axis_A_Squared);
  63.       else {
  64.          derivitive_X -= axis_B_Squared_Times_2;
  65.          active_X -= 1L;
  66.          dd += (derivitive_Y + axis_A_Squared - derivitive_X );
  67.       }
  68.    } /* while ( derivitive_X > derivitive_Y ) */
  69.    
  70.    /*=--------------------------------------------------------------------=*/
  71.    /*   Step along X axis    */
  72.    /*=--------------------------------------------------------------------=*/
  73.    
  74.    dd += ( ( ((3L *(axis_B_Squared-axis_A_Squared)) / 2L) 
  75.              - ( derivitive_X + derivitive_Y ) ) / 2L);
  76.    
  77.    while ( active_X > 0L ) {
  78.       Draw_Patterned_Eastward_Line_Subprimitive(
  79.           (start_X - active_X),(start_Y - active_Y), (active_X << 1) +1);
  80.  
  81.       Draw_Patterned_Eastward_Line_Subprimitive(
  82.          (start_X - active_X),(start_Y + active_Y), (active_X << 1) +1);
  83.  
  84.       active_X -=1;
  85.       derivitive_X -= axis_B_Squared_Times_2;
  86.       
  87.       if (dd > 0L )
  88.          dd  += (axis_B_Squared - derivitive_X);
  89.       else {
  90.          derivitive_Y += axis_A_Squared_Times_2;
  91.          active_Y += 1L;
  92.          dd += (derivitive_Y + axis_B_Squared - derivitive_X );
  93.       }
  94.    } /* while ( active_X > 0L ) */
  95.  
  96.    while (active_Y <= axis_B) {
  97.  
  98.       Draw_Patterned_Eastward_Line_Subprimitive(start_X
  99.          ,(start_Y + active_Y)
  100.           , 1L); /* actually only one pixel */
  101.  
  102.       Draw_Patterned_Eastward_Line_Subprimitive(start_X
  103.                 ,(start_Y - active_Y)
  104.                 , 1L);  /* actually only one pixel */
  105.  
  106.       active_Y += 1L;
  107.    }     
  108. } /* Draw_Filled_Ellipse_Primitive */
  109. /*=********************************************************************=*/
  110.  
  111.  
  112. /*=********************************************************************=*/
  113.  
  114.  
  115. I Guarantee this puppy is FAAAAST. I designed it from various sources.
  116.  
  117. (Draw_Patterned_Eastward_Line_Subprimitive should be written as fast as
  118. you can make it.... or just make it a LineTo.)
  119.  
  120.  
  121. Enjoy.
  122.  
  123. Bill Williams
  124.  
  125.