{original 'Procedure Ellipse2' by Bernie Pallek. Original code by
Sean Palmer}
{but, and I quote, Bernie 'mangled it'}
PROCEDURE Ellipse2(exc, eyc, ea, eb, i, clr : Integer);
VAR
elx, ely : Integer;
aa, aa2, bb, bb2, d, dx, dy : LongInt;
x,y : real;
BEGIN
elx := 0; ely := eb; aa := LongInt(ea) * ea; aa2 := 2 *
aa;
bb := LongInt(eb) * eb; bb2 := 2 * bb;
d := bb - aa * eb + aa DIV 4; dx := 0; dy := aa2 * eb;
x := exc; y := eyc - ely;
rotate(exc,eyc,i,x,y,clr);
x := exc; y := eyc + ely;
rotate(exc,eyc,i,x,y,clr);
x := exc - ea; y := eyc;
rotate(exc,eyc,i,x,y,clr);
x := exc + ea; y := eyc;
rotate(exc,eyc,i,x,y,clr);
WHILE (dx < dy) DO BEGIN
IF (d > 0) THEN BEGIN Dec(ely); Dec(dy, aa2);
Dec(d, dy); END;
Inc(elx); Inc(dx, bb2); Inc(d, bb + dx);
x := exc + elx; y := eyc + ely;
rotate(exc,eyc,i,x,y,clr);
x := exc - elx; y := eyc + ely;
rotate(exc,eyc,i,x,y,clr);
x := exc + elx; y := eyc - ely;
rotate(exc,eyc,i,x,y,clr);
x := exc - elx; y := eyc - ely;
rotate(exc,eyc,i,x,y,clr);
END;
Inc(d, (3 * (aa - bb) DIV 2 - (dx + dy)) DIV 2);
WHILE (ely > 0) DO BEGIN
IF (d < 0) THEN BEGIN Inc(elx); Inc(dx, bb2);
Inc(d, bb + dx); END;
Dec(ely); Dec(dy, aa2); Inc(d, aa - dy);
x := exc + elx; y := eyc + ely;
rotate(exc,eyc,i,x,y,clr);
x := exc - elx; y := eyc + ely;
rotate(exc,eyc,i,x,y,clr);
x := exc + elx; y := eyc - ely;
rotate(exc,eyc,i,x,y,clr);
x := exc - elx; y := eyc - ely;
rotate(exc,eyc,i,x,y,clr);
END;
END;