'=========================================================================== ' Subject: DRAWING ELLIPSES Date: Year of 1993 (00:00:00) ' Author: Rich Geldreich Code: QB, QBasic, PDS ' Keys: DRAW,ELLIPSES Packet: GRAPHICS.ABC '=========================================================================== 'Callable all-integer ellipse routine. 'By Rich Geldreich July 1993 DEFINT A-Z DECLARE SUB DrawEllipse (ox%, oy%, prx%, pry%, co%) SCREEN 13 'the DrawEllipse routine is screen mode independent rx = 51: ry = 51 DO 'test for DrawEllipse DrawEllipse 160, 100, rx, ry, 14 DO: A$ = INKEY$: LOOP UNTIL A$ <> "" DrawEllipse 160, 100, rx, ry, 0 IF LEN(A$) = 2 THEN A = -ASC(RIGHT$(A$, 1)) ELSE A = ASC(A$) END IF SELECT CASE A CASE -72 ry = ry - 3: IF ry < 0 THEN ry = 90 CASE -80 ry = ry + 3: IF ry > 90 THEN ry = 0 CASE -75 rx = rx - 3: IF rx < 0 THEN rx = 150 CASE -77 rx = rx + 3: IF rx > 150 THEN rx = 0 CASE 27 END END SELECT LOOP 'Calling parameters: 'ox, oy = origin 'prx = X radius 'pry = Y radius 'co = color SUB DrawEllipse (ox, oy, prx, pry, co) DIM xe AS LONG, ye AS LONG, e AS LONG IF pry = 0 THEN 'special cases for horizontal & vertical ellipses LINE (ox - prx, oy)-(ox + prx, oy), co EXIT SUB END IF IF prx = 0 THEN LINE (ox, oy - pry)-(ox, oy + pry), co EXIT SUB END IF 'work with largest axis to avoid rounding errors IF pry <= prx THEN x = 0: y = pry xe = 0: ye = CLNG(prx) * prx e = -ye \ 2: c = ye \ pry DO IF e <= 0 THEN DO PSET (ox + x, oy + y), co: PSET (ox - x, oy + y), co PSET (ox + x, oy - y), co: PSET (ox - x, oy - y), co x = x + 1 xe = xe + pry e = e + xe LOOP WHILE e <= 0 ELSE PSET (ox + x, oy + y), co: PSET (ox - x, oy + y), co PSET (ox + x, oy - y), co: PSET (ox - x, oy - y), co END IF y = y - 1 ye = ye - c e = e - ye LOOP UNTIL y = 0 PSET (ox + x, oy), co: PSET (ox - x, oy), co PSET (ox + x, oy), co: PSET (ox - x, oy), co ELSE x = 0: y = prx xe = 0: ye = CLNG(pry) * pry e = -ye \ 2: c = ye \ prx DO IF e <= 0 THEN DO PSET (ox + y, oy + x), co: PSET (ox - y, oy + x), co PSET (ox + y, oy - x), co: PSET (ox - y, oy - x), co x = x + 1 xe = xe + prx e = e + xe LOOP WHILE e <= 0 ELSE PSET (ox + y, oy + x), co: PSET (ox - y, oy + x), co PSET (ox + y, oy - x), co: PSET (ox - y, oy - x), co END IF y = y - 1 ye = ye - c e = e - ye LOOP UNTIL y = 0 PSET (ox, oy + x), co: PSET (ox, oy + x), co PSET (ox, oy - x), co: PSET (ox, oy - x), co END IF END SUB