用void MidPointCircle(int x0,int y0,int x1,int y1,void (*SetPixel)(int x,int y))写中点画圆的代码
时间: 2023-10-14 10:05:19 浏览: 56
void MidPointCircle(int x0, int y0, int x1, int y1, void(*SetPixel)(int x, int y)) {
int r = sqrt(pow((x1 - x0), 2) + pow((y1 - y0), 2)); // 计算圆的半径
int x = 0, y = r;
int d = 1 - r; // 初始决策参数
SetPixel(x0 + x, y0 + y);
SetPixel(x0 - x, y0 + y);
SetPixel(x0 + x, y0 - y);
SetPixel(x0 - x, y0 - y);
SetPixel(x0 + y, y0 + x);
SetPixel(x0 - y, y0 + x);
SetPixel(x0 + y, y0 - x);
SetPixel(x0 - y, y0 - x);
while (x < y) {
if (d < 0) {
d += (x << 1) + 3;
}
else {
d += ((x - y) << 1) + 5;
y--;
}
x++;
SetPixel(x0 + x, y0 + y);
SetPixel(x0 - x, y0 + y);
SetPixel(x0 + x, y0 - y);
SetPixel(x0 - x, y0 - y);
SetPixel(x0 + y, y0 + x);
SetPixel(x0 - y, y0 + x);
SetPixel(x0 + y, y0 - x);
SetPixel(x0 - y, y0 - x);
}
}