From: Jay Link (jlink@interlink-bbs.com)
Date: Sat 04 Dec 1999 - 17:38:09 IST
Hi Everyone, I am planning on submitting the following two functions to Matan for inclusion into SVGAlib 1.4.1. Please let me know if you recommend any changes, fixes, or improvements. gl_fillcircle() is essentially gl_circle, only filled. gl_bcircle() is the Bresenham algorithm contributed by Chris Atenasio, which can be filled or unfilled. It looks good in 320 x 200, which is why I think it's worthwhile. Keep in mind that WIDTH and HEIGHT are defined internally by vgagl. 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_line(sx + x, sy + y, sx - x, sy + y, c); gl_line(sx + x, sy - y, sx - x, sy - y, c); gl_line(sx + y, sy + x, sx - y, sy + x, c); gl_line(sx + y, sy - x, sx - y, sy - x, c); while (x < y) { if (d < 0) { d += x * 2 + 3; } else { d += x * 2 - y * 2 + 5; y--; } x++; gl_line(sx + x, sy + y, sx - x, sy + y, c); gl_line(sx + x, sy - y, sx - x, sy - y, c); gl_line(sx + y, sy + x, sx - y, sy + x, c); gl_line(sx + y, sy - x, sx - y, sy - x, c); } } void gl_bcircle(int sx, int sy, int r, int c, int fill) { int x = 0, y = r, d = 2 * (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; while (y >= 0) { if (fill == 0) { gl_setpixel(sx + x, sy + y, c); gl_setpixel(sx + x, sy - y, c); gl_setpixel(sx - x, sy + y, c); gl_setpixel(sx - x, sy - y, c); } else { gl_line(sx + x, sy + y, sx - x, sy + y, c); gl_line(sx + x, sy - y, sx - x, sy - y, c); } if ((d + y) > 0) { y--; d -= (2 * y * WIDTH / HEIGHT) - 1; } if (x > d) { x++; d += (2 * x) + 1; } } }
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:22 IST