home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power CD-ROM!! 7
/
POWERCD7.ISO
/
prgmming
/
circle_c
/
b-circle.c
next >
Wrap
Text File
|
1994-11-17
|
868b
|
55 lines
/*
Bresenham's circle drawing algorithm
Coded by James Holub, aka Copperhead, of Omega
This routine is completely freeware, you may use it in
anything you want, no credits needed...
*/
void circle(int x, int y, unsigned int r, int color)
{
int xs, ys;
int da, db, s;
xs = 0;
ys = r;
do {
/*
Your pixel-plotting routine goes here. The following example
functions show what the calculations are
my_plot(x+xs, y-ys, color);
my_plot(x+xs, y+ys, color);
my_plot(x-xs, y-ys, color);
my_plot(x-xs, y+ys, color);
my_plot(x+ys, y-xs, color);
my_plot(x+ys, y+xs, color);
my_plot(x-ys, y-xs, color);
my_plot(x-ys, y+xs, color);
*/
da = ((xs + 1) * (xs + 1)) + (ys * ys) - (r * r);
db = ((xs + 1) * (xs + 1)) + ((ys - 1) * (ys - 1)) - (r * r);
s = da + db;
xs++;
if (s > 0)
ys--;
} while (xs <= ys);
}