title: How to write bresenham algorithms in c#?
body: <p>I wrote like this but it works only in 50% cases. Can someone tell what's wrong?</p>
  
  <pre><code>public void Bresenham(int x1,int y1,int x2,int y2,Color c)
          {            
              double dx = x2 - x1;
              double dy = y2 - y1;
              double d = 2*dy-dx; //aux variable
              double p1 = 2 * dy ;
              double p2 = 2 * (dy - dx);
              int x = x1;
              int y = y1;
              int xend;
              c = kolor;
              if (x1 &gt; x2)
              {
                  x = x2;
                  y = y2;
                  xend = x1;
              }
              else
              {
                  x = x1;
                  y = y1;
                  xend = x2;
              }
              bitmapa.SetPixel(x, y,c);
              try
              {
                  while (x &lt; xend)
                  {
                      x++;
                      if (d &lt; 0)
                      {
                          d += p1;
                      }
                      else
                      {
                          d += p2;
                          y += 1;
                      }
                      bitmapa.SetPixel(x, y, c);
                  }
              }
  </code></pre>
  
  <p>Thanks:)</p>