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

  1. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  2.  
  3. procedure StrokeCircle ( xc, yc : integer ; r : word ) ;
  4.  
  5.      { CircDA2 - draw circle using difference angle method }
  6.      {           and semi-circular symmetry with floating  }
  7.      {           point arithmetic                          }
  8.  
  9. var
  10.    ixar,iyar        : word ;    { aspect ratio parameters }
  11.    ar               : single ;  { aspect ratio }
  12.    da,cosda,cosdat2 : single ;  { step angle and functions }
  13.    ida,nda,ndad2    : integer ; { loop control }
  14.    rc               : single ;  { offset radius }
  15.    xa0,xa1,xa2      : single ;  { cosine generator }
  16.    ya0,ya1,ya2      : single ;  { sine generator }
  17.    ix0,iy0,ix1,iy1  : integer ; { display variables }
  18.  
  19. begin
  20.                                 { aspect ratio }
  21.    GetAspectRatio(ixar,iyar) ;
  22.    ar := ixar/iyar ;
  23.                                 { step angle and functions }
  24.    da := 2.0 * sqrt(1.0/r) ;
  25.    nda := Round(2.0 * Pi / da) ;
  26.    if Odd(nda) then Inc(nda) ;
  27.    ndad2 := nda div 2 ;
  28.    da := 2.0 * Pi / nda ;
  29.    cosda := cos(da) ;
  30.    cosdat2 := 2.0 * cosda ;
  31.                                 { initialize differences and     }
  32.                                 { offset, aspect, and reflection }
  33.    rc := r + dr ;
  34.    xa2 := rc * cosda ;
  35.    xa1 := rc ;
  36.    ya2 := -rc * sin(da) * ar ;
  37.    ya1 := 0.0 ;
  38.  
  39.    ix0 := Round(rc) ;
  40.    iy0 := 0 ;
  41.                                 { circle }
  42.    for ida := 1 to ndad2 do begin
  43.                                 { rotate coordinates }
  44.       xa0 := cosdat2 * xa1 - xa2 ;
  45.       ya0 := cosdat2 * ya1 - ya2 ;
  46.                                 { draw chord }
  47.       ix1 := Round(xa0) ;
  48.       iy1 := Round(ya0) ;
  49.                                 { semi-circular symmety }
  50.       Line(xc+ix0,yc+iy0,xc+ix1,yc+iy1) ;
  51.       Line(xc-ix0,yc-iy0,xc-ix1,yc-iy1) ;
  52.                                 { ladder down }
  53.       xa2 := xa1 ;  xa1 := xa0 ;
  54.       ya2 := ya1 ;  ya1 := ya0 ;
  55.       ix0 := ix1 ;  iy0 := iy1
  56.  
  57.    end
  58. end ;
  59.  
  60. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  61.