| void CCGPainterView::DrawCircle(CDC *pDC, CPoint ptOrigin, int iRadius, COLORREF cLineColor) |
| { |
| |
| write the circle algorithm for drawing the circle |
| use function: pDC->SetPixelV (point, cLineColor); to drawing a pixel |
| 编码圆弧生成算法,调用函数 pDC->SetPixelV (point, cLineColor) 画像素。 |
| *************************************************************/ |
| |
| CPoint point; |
| int xi = 0, yi = iRadius; |
| int delta_i = (xi + 1) * (xi + 1) + (yi - 1) * (yi - 1) - iRadius * iRadius; |
| int delta_s; |
| while (yi >= 0) { |
| point.x = ptOrigin.x + xi; |
| point.y = ptOrigin.y + yi; |
| pDC->SetPixelV(point, cLineColor); |
| point.x = ptOrigin.x + xi; |
| point.y = ptOrigin.y - yi; |
| pDC->SetPixelV(point, cLineColor); |
| point.x = ptOrigin.x - xi; |
| point.y = ptOrigin.y + yi; |
| pDC->SetPixelV(point, cLineColor); |
| point.x = ptOrigin.x - xi; |
| point.y = ptOrigin.y - yi; |
| pDC->SetPixelV(point, cLineColor); |
| if (delta_i < 0) { |
| delta_s = 2 * delta_i + 2 * yi - 1; |
| if (delta_s <= 0) { |
| xi = xi + 1; |
| delta_i = delta_i + 2 * xi + 1; |
| } |
| else { |
| xi = xi + 1; |
| yi = yi - 1; |
| delta_i = delta_i + 2 * xi - 2 * yi + 2; |
| } |
| } |
| else if (delta_i > 0) { |
| delta_s = 2 * delta_i - 2 * xi - 1; |
| if (delta_s <= 0) { |
| xi = xi + 1; |
| yi = yi - 1; |
| delta_i = delta_i + 2 * xi - 2 * yi + 2; |
| } |
| else { |
| yi = yi - 1; |
| delta_i = delta_i - 2 * yi + 1; |
| } |
| } |
| else { |
| xi = xi + 1; |
| yi = yi - 1; |
| delta_i = delta_i + 2 * xi - 2 * yi + 2; |
| } |
| } |
| } |