title: How to make a Bresenham's line algorithm?
body: <p>I wrote a small program, that draws a line from user inputs x1,y1 and x2,y2. For some reason line only works while horizontal, but once line should be vertical, it just shows me a black pixel not a line. I have checked everything and I am pretty sure that I got the algorithm right, but problem is still here.</p>
  
  <pre><code>int x1 = Integer.parseInt(this.jTextFieldX1.getText());
      int y1 = Integer.parseInt(this.jTextFieldY1.getText());
      int x2 = Integer.parseInt(this.jTextFieldX2.getText());
      int y2 = Integer.parseInt(this.jTextFieldY2.getText());
  
      int xi = x2 &gt; x1 ? 1:-1;
      int yi = y2 &gt; y1 ? 1:-1;
  
      int dx = Math.abs(x2-x1);
      int dy = Math.abs(y2-y1);
  
      int xn= x1;
      int yn= y1;
      int pn;
      canvas.showBlackPixel(xn,yn);
  
      if (dx &gt; dy)
      {
          pn= 2*dy - dx;
          while (xn != x2)
          {    
          if (pn &gt;0)
          {
              xn=xn + xi;
              yn=yn + yi;
              pn=pn + 2*dy - 2*dx;
  
          }
          else
          {  
                 xn = xn + xi;
                 pn = pn+ 2*dy;
          }
          canvas.showBlackPixel(xn,yn);
          }
          { 
  
          if (dy &gt; dx)
      {
          pn= 2*dx - dy;
          while (yn != y2)
          {    
          if (pn &gt; 0)
          {
              xn=xn + xi;
              yn=yn + yi;
              pn=pn + 2*dx - 2*dy;
  
  
          }
          else
          {  
                 yn = yn + yi;
                 pn = pn + 2*dx;
          }
          canvas.showBlackPixel(xn,yn);
          }
  
          }
  
          }
  
  
  
  
  
  
      }
  
  
  }                                      
  </code></pre>
  
  <p>How could I fix it?</p>