DDA算法画圆代码用c++写
时间: 2023-04-08 13:05:27 浏览: 274
C++画圆算法
我可以回答这个问题。以下是DDA算法画圆的C代码:
#include <graphics.h>
#include <math.h>
void drawCircle(int xc, int yc, int r)
{
int x = 0, y = r;
float d = 1.25 - r;
while(x <= y)
{
putpixel(xc + x, yc + y, WHITE);
putpixel(xc + y, yc + x, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc - y, yc + x, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc + y, yc - x, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc - y, yc - x, WHITE);
if(d < 0)
{
x++;
d += 2 * x + 1;
}
else
{
x++;
y--;
d += 2 * (x - y) + 1;
}
}
}
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int xc = 320, yc = 240, r = 100;
drawCircle(xc, yc, r);
getch();
closegraph();
return 0;
}
阅读全文