c++bresenham算法画圆
时间: 2023-05-13 08:05:29 浏览: 143
bresenham算法画圆
很高兴回答您的问题!C语言中使用Bresenham算法画圆的代码如下:
```c
#include <graphics.h>
#include <conio.h>
#include <dos.h>
void drawCircle(int xc, int yc, int x, int y)
{
putpixel(xc+x, yc+y, RED);
putpixel(xc-x, yc+y, RED);
putpixel(xc+x, yc-y, RED);
putpixel(xc-x, yc-y, RED);
putpixel(xc+y, yc+x, RED);
putpixel(xc-y, yc+x, RED);
putpixel(xc+y, yc-x, RED);
putpixel(xc-y, yc-x, RED);
}
void bresenhamCircle(int xc, int yc, int r)
{
int x = 0, y = r;
int d = 3 - 2 * r;
drawCircle(xc, yc, x, y);
while (y >= x)
{
x++;
if (d > 0)
{
y--;
d = d + 4 * (x - y) + 10;
}
else
{
d = d + 4 * x + 6;
}
drawCircle(xc, yc, x, y);
}
}
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
bresenhamCircle(250, 250, 100);
getch();
closegraph();
return 0;
}
```
这段代码使用Bresenham算法画圆,可以在C语言的图形库中使用。
阅读全文