home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CNC11TP.ZIP / ELIPDAF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-01-19  |  3.2 KB  |  82 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.      { ElipRAF - draw ellipse using difference angle       }
  8.      {           method and fixed point arithmetic         }
  9.  
  10. var
  11.    ixar,iyar        : word ;    { aspect ratio parameters }
  12.    iar              : longint ; { aspect ratio B16 }
  13.    r                : word ;    { effective radius }
  14.    da,cosda         : single ;  { step angle }
  15.    icosda,isinda    : longint ; { step angle functions B16 }
  16.    ida,nda          : integer ; { loop control }
  17.    icosdat2         : longint ; { difference equation coefficient B16 }
  18.    ira,irb          : longint ; { offset radii B6 }
  19.    ixa0,ixa1,ixa2   : longint ; { cosine generator variables B5 }
  20.    iyb0,iyb1,iyb2   : longint ; { sine generator variables B5 }
  21.    icosta,isinta    : longint ; { rotation parameters B11 }
  22.    iacosta,iasinta  : longint ; { rotation parameters B11 }
  23.    ix0,iy0,ix1,iy1  : integer ; { display variables B0 }
  24.  
  25. begin
  26.                                 { constraint test }
  27.    if (a < 510) and (b < 510) then begin
  28.                                 { aspect ratio }
  29.       GetAspectRatio(ixar,iyar) ;
  30.       iar := SwapLong(longint(ixar)) div longint(iyar) ;
  31.                                 { step angle functions }
  32.       if a > b then
  33.          r := a
  34.       else
  35.          r := b ;
  36.       da := 2.0 * sqrt(1.0/r) ;
  37.       nda := Round(2.0 * Pi / da) ;
  38.       if Odd(nda) then Inc(nda) ;
  39.       da := 2.0 * Pi / nda ;
  40.       cosda := cos(da) ;
  41.       icosda := Round(cosda * 65536) ;
  42.       isinda := Round(sin(da) * 65536) ;
  43.       icosdat2 := Round(cosda * 131072) ;
  44.                                 { offset, prescale, reflect }
  45.       ira := a shl 5 + idr div 2 ;
  46.       ixa1 := ira ;
  47.       ixa2 := RoundScaleB16(ira * icosda) ;
  48.       irb := b shl 5 + idr div 2 ;
  49.       iyb1 := 0 ;
  50.       iyb2 := -RoundScaleB16(irb * isinda) ;
  51.                                 { aspect and rotation }
  52.       icosta := Round(cos(ta) * 2048) ;
  53.       isinta := Round(sin(ta) * 2048) ;
  54.       iacosta := RoundScaleB16(iar * icosta) ;
  55.       iasinta := RoundScaleB16(iar * isinta) ;
  56.                                 { starting point }
  57.       ix0 := RoundScaleB16(ixa1 * icosta) ;
  58.       iy0 := -RoundScaleB16(ixa1 * iasinta) ;
  59.       MoveTo(xc+ix0,yc+iy0) ;
  60.                                 { ellipse }
  61.       for ida := 1 to nda-1 do begin
  62.                                 { step coordinates }
  63.          ixa0 := RoundScaleB16(icosdat2 * ixa1) - ixa2 ;
  64.          iyb0 := RoundScaleB16(icosdat2 * iyb1) - iyb2 ;
  65.                                 { rotate }
  66.          ix1 := RoundScaleB16(ixa0 * icosta + iyb0 * isinta) ;
  67.          iy1 := RoundScaleB16(-ixa0 * iasinta + iyb0 * iacosta) ;
  68.                                 { draw stroke }
  69.          LineTo(xc+ix1,yc+iy1) ;
  70.                                 { ladder down }
  71.          ixa2 := ixa1 ;  ixa1 := ixa0 ;
  72.          iyb2 := iyb1 ;  iyb1 := iyb0
  73.  
  74.       end ;
  75.                                 { closure }
  76.       LineTo(xc+ix0,yc+iy0)
  77.  
  78.    end
  79. end ;
  80.  
  81. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  82.