【计算机图形学】圆的中点算法

 
  
// 在CCcView里 添加头文件 #include "DiagCC.h"

// 定义类的对象 DiagCC dcc;


/// //
// CCcView message handlers

void CCcView::CirclePoint( int x, int y, int r, int g, int b)
{ CClientDC dc(
this );
int x0,y0;
x0
= dcc.m_px;
y0
= dcc.m_py;
dc.SetPixel(x
+ x0,y + y0,RGB(r,g,b));
dc.SetPixel(y
+ y0 + x0 - y0,x + x0 + y0 - x0,RGB( 0 , 0 , 255 ));
dc.SetPixel(x
+ x0, - y + y0,RGB(r,g,b));
dc.SetPixel(
- y + y0 + x0 - y0,x + x0 + y0 - x0,RGB( 0 , 255 , 0 ));
dc.SetPixel(
- x + x0,y + y0,RGB(r,g,b));
dc.SetPixel(y
+ y0 + x0 - y0, - x + x0 + y0 - x0,RGB( 255 , 0 , 0 ));
dc.SetPixel(
- x + x0, - y + y0,RGB(r,g,b));
dc.SetPixel(
- y + y0 + x0 - y0, - x + x0 + y0 - x0,RGB(r,g,b));
}

void CCcView::OnDrawcc()
{
// TODO: Add your command handler code here

int x0,y0,radius;
if (dcc.DoModal() == IDOK)
{ radius
= dcc.m_r;
x0
= dcc.m_px;
y0
= dcc.m_py;
}
// mid-point
float d;
int x,y;
x
= 0 ;
y
= radius;
d
= 5.0 / 4 - radius; // 初始化
CirclePoint(x + x0,y + y0,dcc.m_CR,dcc.m_CG,dcc.m_CB);
while (y > x)
{
if (d <= 0 ) d += 2.0 * x + 3 ;
else
{d
+= 2.0 * (x - y) + 5 ;
y
-- ;
}
x
++ ;
CirclePoint(x,y,dcc.m_CR,dcc.m_CG,dcc.m_CB);
}
// end of while

}

2011042916094767.png

转载于:https://www.cnblogs.com/wendychueng/articles/2032886.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值