home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / baswiz19.zip / BW$BAS.ZIP / G13ELLIP.BAS < prev    next >
BASIC Source File  |  1993-01-29  |  2KB  |  63 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        BASWIZ  Copyright (c) 1990-1993  Thomas G. Hanlin III         |
  4. '   |                                                                      |
  5. '   |                      The BASIC Wizard's Library                      |
  6. '   |                                                                      |
  7. '   +----------------------------------------------------------------------+
  8.  
  9. ' this routine is based on the midpoint ellipse algorithm as expressed in the
  10. ' book "Programmer's Guide to PC & PS/2 Video Displays", by Richard Wilton,
  11. ' Microsoft Press.
  12.  
  13.    DECLARE SUB G13Line (BYVAL X1%, BYVAL Y1%, BYVAL X2%, BYVAL Y2%)
  14.    DECLARE SUB G13Plot (BYVAL X%, BYVAL Y%)
  15.  
  16.    DEFINT A-Z
  17.  
  18. SUB G13Ellipse (CenterX, CenterY, XRad, YRadius)
  19.    XRadius = XRad * 1.2
  20.    IF XRadius = 0 THEN
  21.       G13Line CenterX, CenterY - YRadius, CenterX, CenterY + YRadius
  22.    ELSEIF YRadius = 0 THEN
  23.       G13Line CenterX - XRadius, CenterY, CenterX + XRadius, CenterY
  24.    ELSE
  25.       X = 0
  26.       Y = YRadius
  27.       A& = XRadius
  28.       B& = YRadius
  29.       D& = B& * B& - A& * A& * B& + (A& * A&) \ 4&
  30.       DX& = 0&
  31.       DY& = 2 * A& * A& * B&
  32.       DO WHILE DX& < DY&
  33.          G13Plot CenterX + X, CenterY + Y
  34.          G13Plot CenterX + X, CenterY - Y
  35.          G13Plot CenterX - X, CenterY + Y
  36.          G13Plot CenterX - X, CenterY - Y
  37.          IF D& > 0& THEN
  38.             Y = Y - 1
  39.             DY& = DY& - 2& * A& * A&
  40.             D& = D& - DY&
  41.          END IF
  42.          X = X + 1
  43.          DX& = DX& + 2& * B& * B&
  44.          D& = D& + B& * B& + DX&
  45.       LOOP
  46.       D& = D& + (3& * (A& * A& - B& * B&) \ 2& - (DX& + DY&)) \ 2&
  47.       DO WHILE Y >= 0
  48.          G13Plot CenterX + X, CenterY + Y
  49.          G13Plot CenterX + X, CenterY - Y
  50.          G13Plot CenterX - X, CenterY + Y
  51.          G13Plot CenterX - X, CenterY - Y
  52.          IF D& < 0& THEN
  53.             X = X + 1
  54.             DX& = DX& + B& * B& * 2&
  55.             D& = D& + DX&
  56.          END IF
  57.          Y = Y - 1
  58.          DY& = DY& - A& * A& * 2&
  59.          D& = D& + A& * A& - DY&
  60.       LOOP
  61.    END IF
  62. END SUB
  63.