- A little game for showcasing the Line Drawing Algorithm
- The Line Drawing Algorithm helps us to find the intercept between a line and a circle
private IEnumerable DrawingLine(int x, int y, int x2, int y2) { int w = x2 - x; int h = y2 - y; int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0; if (w < 0) dx1 = -1; else if (w > 0) dx1 = 1; if (h < 0) dy1 = -1; else if (h > 0) dy1 = 1; if (w < 0) dx2 = -1; else if (w > 0) dx2 = 1; int longest = Math.Abs(w); int shortest = Math.Abs(h); if (!(longest > shortest)) { longest = Math.Abs(h); shortest = Math.Abs(w); if (h < 0) dy2 = -1; else if (h > 0) dy2 = 1; dx2 = 0; } int numerator = longest >> 1; for (int i = 0; i <= longest; i++) { yield return new Point(x, y); numerator += shortest; if (!(numerator < longest)) { numerator -= longest; x += dx1; y += dy1; } else { x += dx2; y += dy2; } } }