public static void DrawScreenCircle(this FrameState frame, int x0, int y0, int radius, Color color) { void DrawPoint(int xn, int yn) { frame.DrawScreenPoint(xn, yn, color); } var x = radius; var y = 0; var radiusError = 1 - x; while (x >= y) { DrawPoint(x + x0, y + y0); DrawPoint(y + x0, x + y0); DrawPoint(-x + x0, y + y0); DrawPoint(-y + x0, x + y0); DrawPoint(-x + x0, -y + y0); DrawPoint(-y + x0, -x + y0); DrawPoint(x + x0, -y + y0); DrawPoint(y + x0, -x + y0); y++; if (radiusError < 0) { radiusError += 2 * y + 1; } else { x--; radiusError += 2 * (y - x + 1); } } }
public static void DrawScreenLineSmooth(this FrameState frame, int x0, int y0, int x1, int y1, Color color) { void DrawScreenPoint(bool swap, int vx, int vy, float intensity) { if (swap) { Common.Swap(ref vx, ref vy); } frame.DrawScreenPoint(vx, vy, color.ChangeAlpha((byte)(intensity * color.A))); } var steep = NormalizeLine(ref x0, ref y0, ref x1, ref y1); DrawScreenPoint(steep, x0, y0, 1); DrawScreenPoint(steep, x1, y1, 1); var dx = x1 - x0; var dy = y1 - y0; var gradient = (float)dy / dx; var y = y0 + gradient; for (var x = x0 + 1; x < x1; x++) { DrawScreenPoint(steep, x, (int)y, 1 - (y - (int)y)); DrawScreenPoint(steep, x, (int)y + 1, y - (int)y); y += gradient; } }
public static void DrawScreenLine(this FrameState frame, int x0, int y0, int x1, int y1, Color color) { var steep = NormalizeLine(ref x0, ref y0, ref x1, ref y1); var dx = x1 - x0; var dy = Math.Abs(y1 - y0); var error = dx / 2; var ystep = (y0 < y1) ? 1 : -1; var y = y0; for (var x = x0; x <= x1; x++) { frame.DrawScreenPoint(steep ? y : x, steep ? x : y, color); error -= dy; if (error < 0) { y += ystep; error += dx; } } }