gpt-3.5-turbo-0301· openai
WildChat-4.8M
Fix the code. (The DrawCircle part.) namespace bresenhamCircle { public partial class…
- User
Fix the code. (The DrawCircle part.) namespace bresenhamCircle { public partial class Form1 : Form { private int x1, y1, x2, y2;
codepublic 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
There are several issues with the DrawCircle method. Here is the corrected code:
private void DrawCircle(int x1, int y1, int x2, int y2) { pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics g = Graphics.FromImage(pictureBox1.Image);
codeint radius = (int)Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)); int x = 0; int y = radius; int delta = 1 - 2 * radius; int error = 0; while (y >= 0) { g.FillRectangle(Brushes.Black, x1 + x, y1 + y, 1, 1); g.FillRectangle(Brushes.Black, x1 + x, y1 - y, 1, 1); g.FillRectangle(Brushes.Black, x1 - x, y1 + y, 1, 1); g.FillRectangle(Brushes.Black, x1 - x, y1 - y, 1, 1); error = 2 * (delta + y) - 1; if (delta < 0 && error <= 0) { delta += 2 * ++x + 1; continue; } error = 2 * (delta - x) - 1; if (delta > 0 && error > 0) { delta += 1 - 2 * --y; continue; } x++; delta += 2 * (x - y); y--; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.