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

  1. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  2.  
  3. procedure StrokeEllipse ( xc, yc : integer ; { center }
  4.                             a, b : word ; { radii }
  5.                               ta : single ) ; { rotation angle (rad) }
  6.  
  7.      { ElipRAF2 - draw ellipse using rotation angle method }
  8.      {            with fixed point arithmetic and semi-    }
  9.      {            circular symmetry                        }
  10.  
  11. var
  12.    ixar,iyar        : word ;    { aspect ratio parameters }
  13.    iar              : longint ; { aspect ratio B16 }
  14.    da               : single ;  { step angle }
  15.    icosda,isinda    : longint ; { step angle functions B16 }
  16.    ira,irb          : longint ; { offset radii B6 }
  17.    icosta,isinta    : longint ; { rotation variables B16 }
  18.    it,ixa,iya       : longint ; { coordinate variables B6 }
  19.    ixb,iyb          : longint ; { coordinate variables B6 }
  20.    r,ida,ndad2      : integer ; { loop control }
  21.    ix0,iy0,ix1,iy1  : integer ; { display variables B0 }
  22.  
  23. begin
  24.                                 { constraint test }
  25.    if (a < 511) and (b < 511) then begin
  26.                                 { aspect ratio }
  27.       GetAspectRatio(ixar,iyar) ;
  28.       iar := SwapLong(longint(ixar)) div longint(iyar) ;
  29.                                 { step angle and functions }
  30.       if a > b then
  31.          r := a
  32.       else
  33.          r := b ;
  34.       da := 2.0 * sqrt(1.0/r) ;
  35.       ndad2 := Round(Pi / da) ;
  36.       da := Pi / ndad2 ;
  37.       icosda := Round(cos(da) * 65536) ;
  38.       isinda := Round(sin(da) * 65536) ;
  39.                                 { offset and scale radii }
  40.       ira := a shl 6 + idr ;
  41.       irb := b shl 6 + idr ;
  42.                                 { scale rotation functions }
  43.       icosta := Round(cos(ta) * 65536) ;
  44.       isinta := Round(sin(ta) * 65536) ;
  45.                                 { coordinate variables with        }
  46.                                 { rotation, aspect, and reflection }
  47.       ixa := RoundScaleB16(ira * icosta) ;
  48.       iya := -RoundScaleB16(irb * isinta) ;
  49.       ixb := RoundScaleB16(RoundScaleB16(irb * icosta) * iar) ;
  50.       iyb := -RoundScaleB16(RoundScaleB16(ira * isinta) * iar) ;
  51.                                 { starting point }
  52.       ix0 := RoundScaleB6(ixa) ;
  53.       iy0 := RoundScaleB6(iyb) ;
  54.                                 { ellipse }
  55.       for ida := 1 to ndad2 do begin
  56.                                 { rotate coordinates }
  57.          it := RoundScaleB16(ixa * icosda - iya * isinda) ;
  58.          iya := RoundScaleB16(ixa * isinda + iya * icosda) ;
  59.          ixa := it ;
  60.  
  61.          it := RoundScaleB16(ixb * icosda - iyb * isinda) ;
  62.          iyb := RoundScaleB16(ixb * isinda + iyb * icosda) ;
  63.          ixb := it ;
  64.                                 { semi-elliptic symmetry }
  65.          ix1 := RoundScaleB6(ixa) ;
  66.          iy1 := RoundScaleB6(iyb) ;
  67.          Line(xc+ix0,yc+iy0,xc+ix1,yc+iy1) ;
  68.          Line(xc-ix0,yc-iy0,xc-ix1,yc-iy1) ;
  69.                                 { ladder down }
  70.          ix0 := ix1 ;  iy0 := iy1
  71.  
  72.       end
  73.    end
  74. end ;
  75.  
  76. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  77.