'i wanted to implement C# Bresenham's line algorithm but it just draw horizontal lines , i want it to draw lines with angles as i saw in many tutorials

what i got when i run it

here's my code i take input from user to draw line using brenesham but it just draw horizontal line even when i tried with many values i have same issue so i want it to draw line with angel as i saw in my tutorials where they implement it with angles not just horizontal angel

private void button2_Click(object sender, EventArgs e)
        {
            int x1 = Convert.ToInt32(textBox5.Text);
            int y1 = Convert.ToInt32(textBox6.Text);

            int x2 = Convert.ToInt32(textBox7.Text);
            int y2 = Convert.ToInt32(textBox8.Text);

            Point p1 = new Point(x1, y1);
            Point p2 = new Point(x2, y2);

            Bresenham_Line(p1, p2);
        }
private void Bresenham_Line(Point p1, Point p2)
        {
            double x, y, x2, y2;
            Bitmap pp = new Bitmap(this.Width, this.Height);

            double dx = p2.X - p1.X;
            double dy = p2.Y - p2.Y;
            double p = 2 * (dy - dx);
            double c1 = 2 * dy;
            double c2 = 2 * (dy - dx);

           
            x = p1.X; y = p1.Y;
            
            pp.SetPixel((int)x, (int)y, Color.Blue);
           
            x2 = p2.X; y2 = p2.Y;

            while (x < x2)
            {
                
                if (p < 0)
                {
                    p += c1;
                }
                else
                {
                    p += c2;
                    y += 1;
                }

                x++;

                pp.SetPixel((int)x, (int)y, Color.Black);
            }


            pictureBox1.Image = pp;


        }

i added photo from what i get when i run it



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source