home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CNC11TP.ZIP / CIRCRAF4.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-01-19  |  2.2 KB  |  59 lines

  1. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  2.  
  3. procedure StrokeCircle ( xc, yc : integer ; r : word ) ;
  4.  
  5.      { CircRAF4 - draw circle using rotation angle method, }
  6.      {            fixed point arithmetic, and quadrant     }
  7.      {            symmetry                                 }
  8.  
  9. var
  10.    ixar,iyar        : word ;    { aspect ratio parameters }
  11.    iar              : longint ; { aspect ratio B16 }
  12.    da               : single ;  { step angle }
  13.    icosda,isinda    : longint ; { step angle functions B16 }
  14.    ida,nda,ndad4    : integer ; { loop control }
  15.    it,ix,iy         : longint ; { coordinate variables B6 }
  16.    ix0,iy0,ix1,iy1  : integer ; { display variables }
  17.  
  18. begin
  19.                                 { constraint test }
  20.    if r < 512 then begin
  21.                                 { aspect ratio }
  22.       GetAspectRatio(ixar,iyar) ;
  23.       iar := SwapLong(longint(ixar)) div longint(iyar) ;
  24.                                 { step angle and functions }
  25.       da := 2.0 * sqrt(1.0/r) ;
  26.       nda := Round(2.0 * Pi / da) ;
  27.       ndad4 := (nda + 3) div 4 ;
  28.       nda := ndad4 shl 2 ;
  29.       da := 2.0 * Pi / nda ;
  30.       icosda := Round(cos(da) * 65536) ;
  31.       isinda := Round(sin(da) * 65536) ;
  32.                                 { starting point with offset }
  33.       ix := r shl 6 + idr ;
  34.       iy := 0 ;
  35.       ix0 := RoundScaleB6(ix) ;
  36.       iy0 := 0 ;
  37.                                 { circle }
  38.       for ida := 1 to ndad4 do begin
  39.                                 { rotate coordinates }
  40.          it := RoundScaleB16(ix * icosda - iy * isinda) ;
  41.          iy := RoundScaleB16(ix * isinda + iy * icosda) ;
  42.          ix := it ;
  43.                                 { aspect ratio }
  44.          ix1 := RoundScaleB6(ix) ;
  45.          iy1 := RoundScaleB6(LongHi(iy * iar)) ;
  46.                                 { quadrant symmety }
  47.          Line(xc+ix0,yc+iy0,xc+ix1,yc+iy1) ;
  48.          Line(xc-ix0,yc+iy0,xc-ix1,yc+iy1) ;
  49.          Line(xc-ix0,yc-iy0,xc-ix1,yc-iy1) ;
  50.          Line(xc+ix0,yc-iy0,xc+ix1,yc-iy1) ;
  51.                                 { ladder down }
  52.          ix0 := ix1 ;  iy0 := iy1
  53.  
  54.       end
  55.    end
  56. end ;
  57.  
  58. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  59.