Fix the code. (The DrawCircle part.) Don't change it too much. Just fix the radius…
- User
Fix the code. (The DrawCircle part.) Don't change it too much. Just fix the radius calculating and the x and y so they was based on x1 and x2. namespace bresenhamCircle { public partial class Form1 : Form
{ private int x1, y1, x2, y2;public Form1() { InitializeComponent();
} private void pictureBox1_Click(object sender, EventArgs e) { if (x1 != 0 && y1 != 0) { x2 = (int)((MouseEventArgs)e).X; y2 = (int)((MouseEventArgs)e).Y;
DrawCircle(x1, y1, x2, y2);
x1 = 0; y1 = 0; x2 = 0; y2 = 0; } else { x1 = (int)((MouseEventArgs)e).X; y1 = (int)((MouseEventArgs)e).Y; } }
private void DrawCircle(int x1, int y1, int x2, int y2)
{ pictureBox1.Image = (Image)new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics g = Graphics.FromImage(pictureBox1.Image); int r = 0; //radius ???
int x = x1; int y = y1; x = -r; // ??? y = 0; //??? int F = 1 - r; int delFs = 3; int delFd = 5 - 2 * r; while (x + y < 0) { g.FillRectangle(Brushes.Black, x, y, 1, 1); if (F > 0) { //Диагональное смещение. F += delFd; x++; y++; delFs += 2; delFd += 4; } else { //Вертикальное смешение. F += delFs; y++; delFs += 2; delFd += 2; } } }
} }
- Assistant
namespace bresenhamCircle { public partial class Form1 : Form { private int x1, y1, x2, y2;
code