1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| void CTest1View::Onbresenham() { int x0 = 0, y0 = 0, x1 = 300, y1 = 600, color = 159; int dx, dy, cou, k,f; CClientDC cc(this); int x, y, increase0, increase1; dx = abs(x0 - x1); dy = abs(y0 - y1); f = 2 * dy - dx; x = x0, y = y0; cou = max(dx, dy); increase0 = 2 * (dy - dx); increase1 = 2 * dy; for (int i = 0; i <= cou; i++) { cc.SetPixel(x, y, color); if (f < 0) { f += increase1; } else { y++; f += increase0; } x++; } }
|