home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CNC11TP.ZIP / ELIPRA2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-01-19  |  2.1 KB  |  64 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.      { ElipRA2 - draw ellipse using rotation angle method  }
  8.      {           and semi-circular symmetry                }
  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.    t,xa,ya,xb,yb    : single ;  { coordinate variables }
  15.    r,ida,ndad2      : integer ; { loop control }
  16.    ix0,iy0,ix1,iy1  : integer ; { display variables }
  17.  
  18. begin
  19.                                 { aspect ratio }
  20.    GetAspectRatio(ixar,iyar) ;
  21.    ar := ixar/iyar ;
  22.                                 { step angle and functions }
  23.    if a > b then
  24.       r := a
  25.    else
  26.       r := b ;
  27.    da := 2.0 * sqrt(1.0/r) ;
  28.    ndad2 := Round(Pi / da) ;
  29.    da := Pi / ndad2 ;
  30.    cosda := cos(da) ;
  31.    sinda := sin(da) ;
  32.                                 { coordinate variables with }
  33.                                 { rotation, offset, aspect, }
  34.                                 { and reflection            }
  35.    xa := (a+dr) * cos(ta) ;
  36.    ya := -(b+dr) * sin(ta) ;
  37.    xb := (b+dr) * cos(ta) * ar ;
  38.    yb := -(a+dr) * sin(ta) * ar ;
  39.                                 { starting point }
  40.    ix0 := Round(xa) ;
  41.    iy0 := Round(yb) ;
  42.                                 { ellipse }
  43.    for ida := 1 to ndad2 do begin
  44.                                 { rotate coordinates }
  45.       t := xa * cosda - ya * sinda ;
  46.       ya := xa * sinda + ya * cosda ;
  47.       xa := t ;
  48.  
  49.       t := xb * cosda - yb * sinda ;
  50.       yb := xb * sinda + yb * cosda ;
  51.       xb := t ;
  52.                                 { semi-circular symmetry }
  53.       ix1 := Round(xa) ;
  54.       iy1 := Round(yb) ;
  55.       Line(xc+ix0,yc+iy0,xc+ix1,yc+iy1) ;
  56.       Line(xc-ix0,yc-iy0,xc-ix1,yc-iy1) ;
  57.                                 { ladder down }
  58.       ix0 := ix1 ;  iy0 := iy1
  59.  
  60.    end
  61. end ;
  62.  
  63. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  64.