home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CNC11TP.ZIP / POLYRA.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-01-19  |  1.6 KB  |  45 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.      { PolyRA - draw regular polygon using rotation angle  }
  8.      {          method and floating point arithemtic       }
  9.  
  10. var
  11.    ixar,iyar        : word ;    { aspect ratio parameters }
  12.    ar               : single ;  { aspect ratio }
  13.    da,cosda,sinda   : single ;  { step angle and functions }
  14.    i                : integer ; { loop control }
  15.    t,x,y            : single ;  { coordinate variables }
  16.  
  17. begin
  18.                                 { constraint test }
  19.    if (r > 0) and (n > 2) then begin
  20.                                 { aspect ratio }
  21.       GetAspectRatio(ixar,iyar) ;
  22.       ar := ixar/iyar ;
  23.                                 { step angle and functions }
  24.       da := 2.0 * Pi / n ;
  25.       cosda := cos(da) ;
  26.       sinda := sin(da) ;
  27.                                 { starting point with offset }
  28.       x := r * cos(ta) ;
  29.       y := -r * sin(ta) ;
  30.       MoveTo(xc+Round(x),yc+Round(y*ar)) ;
  31.                                 { polygon }
  32.       for i := 1 to n do begin
  33.                                 { rotate coordinates }
  34.          t := x * cosda - y * sinda ;
  35.          y := x * sinda + y * cosda ;
  36.          x := t ;
  37.                                 { apply aspect ratio }
  38.          LineTo(xc+Round(x),yc+Round(y*ar))
  39.  
  40.       end
  41.    end
  42. end ;
  43.  
  44. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  45.