Improved gl_fillcircle()

Search this archive.

From: Jay Link (jlink@interlink-bbs.com)
Date: Sat 04 Dec 1999 - 22:06:36 IST


Hi Matan,

Well, stupid me, Chris Atenasio has helped me to figure out how to make
the two new functions work with gl_hline() instead of gl_line(). So,
please replace the gl_fillcircle() I sent you earlier with this. The man
pages and all will remain the same. Thank you! I will look into your
suggestion on gl_bcircle() now re: aspect ratios.


void gl_fillcircle(int sx, int sy, int r, int c)
{
    int x = 0,
        y = r,
        d = 1 - r;

    if (r < 1) {
	gl_setpixel(sx, sy, c);
	return;
    }
    if (__clip)
	if (sx + r < __clipx1 || sx - r > __clipx2
	    || sy + r < __clipy1 || sy - r > __clipy2)
	    return;
    gl_hline(sx - x, sy + y, sx + x, c);
    gl_hline(sx - x, sy - y, sx + x, c);
    gl_hline(sx - y, sy + x, sx + y, c);
    gl_hline(sx - y, sy - x, sx + y, c);
    while (x < y)
    {
        if (d < 0)
        {
            d += x * 2 + 3;
        } else {
            d += x * 2 - y * 2 + 5;
            y--;
        }
        x++;
        gl_hline(sx - x, sy + y, sx + x, c);
        gl_hline(sx - x, sy - y, sx + x, c);
        gl_hline(sx - y, sy + x, sx + y, c);
        gl_hline(sx - y, sy - x, sx + y, c);
    }
}


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:22 IST