home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / CIRCLEX.OPL < prev    next >
Text File  |  1993-03-31  |  3KB  |  82 lines

  1.  
  2. Ä Area: [FIDO] PSION echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  3.   Msg#: 7345                                         Date: 03-30-93  17:55
  4.   From: Bj“rn Felten                                 Read: Yes    Replied: No 
  5.     To: Michael Cronsten                             Mark:                     
  6.   Subj: Ringplotting.
  7. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  8. Hi MiCro, 
  9.  
  10.    In the swedish PSION-conference, you asked for a routine to draw a circle on
  11. the S3. I hope you don't mind my answering your question here in the int'l
  12. ditto to make the information available to more than the few readers of our
  13. swedish conference. 
  14.  
  15.    There are several tricks you can use to get a circle procedure that don't
  16. take all day to draw a circle. 
  17.  
  18.    Pro primo, you only calculate one eighth of the coordinates, the symmetry of
  19. the circle makes it possible to get the other coordinates by means of a simple
  20. combination of positive and negative numbers. 
  21.  
  22.    Pro secundo, you avoid trigonometric functions since they are very time
  23. consuming. 
  24.  
  25.    Another trick to use is setting up varios kinds of arrays, but I will not go
  26. into that here. You also can experiment with gPOLY to get slightly faster
  27. procedures. 
  28.  
  29.    Below you find an example using the first two tricks (CIRCLE.OPL also can be
  30. downloaded/requested from -=P=I=X=-): 
  31.  
  32.  
  33. proc TestCirc: 
  34.   Circle:(120, 40, 30) 
  35.   get 
  36. endp 
  37.  
  38. proc Circle:(x0%, y0%, r%) 
  39. rem Fast code for drawing a circle. Doesn't use any trigonometric functions. 
  40. rem Based on the circle's equation (x - x0)^2 + (y - y0)^2 = r^2, where 
  41. rem (x0, y0) is the center and r the radius. 
  42.  
  43. local x%, y%, r2%, x2%, y2% 
  44.  
  45.   r2% = r% * r% 
  46.   x%  = r% 
  47.   x2% = r2% - x% 
  48.  
  49.   while x% + 1 > y% 
  50.     Put8Pix:(x0%, y0%, x%, y%) 
  51.     y2% = y2% + y% + y% + 1 
  52.     y%  = y% + 1 
  53.     if x2% > (r2% - y2%) 
  54.        x2% = x2% - x% - x% + 1 
  55.        x%  = x% - 1 
  56.     endif 
  57.   endwh 
  58. endp 
  59.  
  60. proc Put8Pix:(x0%, y0%, x%, y%) 
  61. rem Thanks to the symmetry of the circle, we can put eight 
  62. rem pixels from one set of values. 
  63.  
  64.   PutPix:(x0%+x%, y0%+y%) 
  65.   PutPix:(x0%-x%, y0%+y%) 
  66.   PutPix:(x0%+x%, y0%-y%) 
  67.   PutPix:(x0%-x%, y0%-y%) 
  68.   PutPix:(x0%+y%, y0%+x%) 
  69.   PutPix:(x0%-y%, y0%+x%) 
  70.   PutPix:(x0%+y%, y0%-x%) 
  71.   PutPix:(x0%-y%, y0%-x%) 
  72. endp 
  73.  
  74. proc PutPix:(x%, y%) 
  75.   gAT x%, y% 
  76.   gLINEBY 0, 0 
  77. endp  
  78.   
  79. -!-
  80.  ! Origin: -=P=I=X=- / Psion Info Xchange  +46-31-960447 (2:203/208)
  81.  
  82.