(proc is the equivalent to a putpixel function. this is strictly out of the Allegro graphics library)
/* do_ellipse: * Helper function for the ellipse drawing routines. Calculates the points * in an ellipse of radius rx and ry around point x, y, and calls the * specified routine for each one. The output proc will be passed first a * copy of the bmp parameter, then the x, y point, then a copy of the d * parameter (so putpixel() can be used as the callback). */void do_ellipse(BITMAP *bmp, int x, int y, int rx, int ry, int d, void (*proc)()){ int ix, iy; int h, i, j, k; int oh, oi, oj, ok; if (rx < 1) rx = 1; if (ry < 1) ry = 1; h = i = j = k = 0xFFFF; if (rx > ry) { ix = 0; iy = rx * 64; do { oh = h; oi = i; oj = j; ok = k; h = (ix + 32) >> 6; i = (iy + 32) >> 6; j = (h * ry) / rx; k = (i * ry) / rx; if (((h != oh) | | (k != ok)) && (h < oi)) { proc(bmp, x+h, y+k, d); if (h) proc(bmp, x-h, y+k, d); if (k) { proc(bmp, x+h, y-k, d); if (h) proc(bmp, x-h, y-k, d); } } if (((i != oi) | | (j != oj)) && (h < i)) { proc(bmp, x+i, y+j, d); if (i) proc(bmp, x-i, y+j, d); if (j) { proc(bmp, x+i, y-j, d); if (i) proc(bmp, x-i, y-j, d); } } ix = ix + iy / rx; iy = iy - ix / rx; } while (i > h); } else { ix = 0; iy = ry * 64; do { oh = h; oi = i; oj = j; ok = k; h = (ix + 32) >> 6; i = (iy + 32) >> 6; j = (h * rx) / ry; k = (i * rx) / ry; if (((j != oj) | | (i != oi)) && (h < i)) { proc(bmp, x+j, y+i, d); if (j) proc(bmp, x-j, y+i, d); if (i) { proc(bmp, x+j, y-i, d); if (j) proc(bmp, x-j, y-i, d); } } if (((k != ok) | | (h != oh)) && (h < oi)) { proc(bmp, x+k, y+h, d); if (k) proc(bmp, x-k, y+h, d); if (h) { proc(bmp, x+k, y-h, d); if (k) proc(bmp, x-k, y-h, d); } } ix = ix + iy / ry; iy = iy - ix / ry; } while(i > h); }}/* ellipse: * Draws an ellipse. */void ellipse(BITMAP *bmp, int x, int y, int rx, int ry, int color){ int clip, sx, sy, dx, dy; if (bmp->clip) { sx = x-rx-1; sy = y-ry-1; dx = x+rx+1; dy = y+ry+1; if ((sx >= bmp->cr) | | (sy >= bmp->cb) | | (dx < bmp->cl) | | (dy < bmp->ct)) return; if ((sx >= bmp->cl) && (sy >= bmp->ct) && (dx < bmp->cr) && (dy < bmp->cb)) bmp->clip = FALSE; clip = TRUE; } else clip = FALSE; do_ellipse(bmp, x, y, rx, ry, color, bmp->vtable->putpixel); bmp->clip = clip;}