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

  1. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  2.  
  3. procedure StrokePolygon ( xc, yc : integer ; { center }
  4.                             r, n : word ; { radius and number of sides }
  5.                               ta : single ) ; { rotation angle (rad) }
  6.  
  7.      { PolyRAF - draw regular polygon using rotation angle }
  8.      {           method and fixed point arithmetic         }
  9.  
  10. var
  11.    ixar,iyar        : word ;    { aspect ratio parameters }
  12.    iar              : longint ; { aspect ratio B16 }
  13.    da               : single ;  { step angle }
  14.    icosda,isinda    : longint ; { step angle functions B16 }
  15.    ir               : longint ; { scaled radius B6 }
  16.    icosta,isinta    : longint ; { rotation angle functions B16 }
  17.    is               : integer ; { loop control }
  18.    it,ix,iy         : longint ; { coordinate variables B6 }
  19.    ix0,iy0,ix1,iy1  : integer ; { display variables B0 }
  20.  
  21. begin
  22.                                 { constraint test }
  23.    if (r > 0) and (r < 512) and (n > 2) then begin
  24.                                 { aspect ratio }
  25.       GetAspectRatio(ixar,iyar) ;
  26.       iar := SwapLong(longint(ixar)) div longint(iyar) ;
  27.                                 { step angle and functions }
  28.       da := 2.0 * Pi / n ;
  29.       icosda := Round(cos(da) * 65536) ;
  30.       isinda := Round(sin(da) * 65536) ;
  31.                                 { scaled radius }
  32.       ir := r shl 6 ;
  33.                                 { rotation functions }
  34.       icosta := Round(cos(ta) * 65536) ;
  35.       isinta := Round(sin(ta) * 65536) ;
  36.  
  37.       ix := RoundScaleB16(ir * icosta) ;
  38.       iy := -RoundScaleB16(ir * isinta) ;
  39.       ix0 := RoundScaleB6(ix) ;
  40.       iy0 := RoundScaleB6(LongHi(iy*iar)) ;
  41.       MoveTo(xc+ix0,yc+iy0) ;
  42.                                 { polygon }
  43.       for is := 1 to n-1 do begin
  44.                                 { rotate coordinates }
  45.          it := RoundScaleB16(ix * icosda - iy * isinda) ;
  46.          iy := RoundScaleB16(ix * isinda + iy * icosda) ;
  47.          ix := it ;
  48.                                 { apply aspect ratio }
  49.          ix1 := RoundScaleB6(ix) ;
  50.          iy1 := RoundScaleB6(LongHi(iy*iar)) ;
  51.          LineTo(xc+ix1,yc+iy1) ;
  52.  
  53.       end ;
  54.                                 { closure }
  55.       LineTo(xc+ix0,yc+iy0)
  56.  
  57.    end
  58. end ;
  59.  
  60. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  61.