to konista(M) 大哥,我改了一下,结果打印的不是圆哦,请问错在那里?void DrawPoint(int x, int y) { //在屏幕的x,y位置画点 printf("%s","."); }打印结果 ................................................................................ ................................................................................ ............................................Press any key to continue
pDC没有画圆的函数吗?
Ellipse把参数设好就可以了!
Arc()
ArcTo()
只画线
pDC->Arc(CRect(0,0,width,height),CPoint(0,height/2),CPoint(1,height/2-1));
int GetY(int x)
{
return int(sqrt(50 ^ 2 - (50 - x) ^ 2));
}
void DrawPoint(int x, int y)
{
//在屏幕的x,y位置画点
}
main()
{
for (int x = 0; x <= 50; x++)
{
int y = GetY(x);
DrawPoint(x, y);
DrawPoint(100 - x, y);
DrawPoint(x, 100 - y);
DrawPoint(100 - x, 100 - y);
}
}
要画圆的算法是吧,这个爽吧!hahahaha
GetY(int x)里的返回应该是
return int(50 - sqrt(50 ^ 2 - (50 - x) ^2)));
{
//在屏幕的x,y位置画点
printf("%s",".");
}打印结果
................................................................................
................................................................................
............................................Press any key to continue
那用什么啊,,,,
api也不用?
给只铅笔吧,,^_^,开玩笑,
那可以用什么?
可以根据圆的公式和坐标,打点,不过也得用到cdc,其他的就不知道了!
这个是原点为圆心1/4圆,其它部分可以坐标变换得到BresenhamCircle(r, color)
int r, color;
{
int x, y, delta, delta1, delta2, direction;
x = 0;
y = r;
delta = 2*(1-r);
while (y >= 0)
{
drawpixel(x, y, color);
if (delta < 0)
{
delta1 = 2*(delta+y)-1;
if (delta1 <= 0) direction = 1;
else direction = 2;
}
else if (delta > 0)
{
delta2 = 2*(delta-x)-1;
if (delta2 <= 0) direction = 2;
else direction = 3;
}
else
direction = 2;
switch (direction)
{
case 1:
x++;
delta += 2*x+1;
break;
case 2:
x++;
y--;
delta += 2*(x-y+1);
break;
case 3:
y--;
delta += (-2*y+1);
break;
}
}
}