title: Using Bresenham’s algorithm to create a line
body: <p>I'm running into an issue where a line can be drawn if the slope is less than 1, but once the slope is greater, the line still draws a slope of 1.
  <a href="https://i.stack.imgur.com/cWMKi.png" rel="nofollow noreferrer">(0,0) to (70,25)</a>
  <a href="https://i.stack.imgur.com/IpghT.png" rel="nofollow noreferrer">(0,0) to (25,70)</a>
  I'm following some specific pseudocode, which is why I have so many variable assignments.</p>
  <pre class="lang-cpp prettyprint-override"><code>void drawLine(Point a, Point b){
      int x1 = a.first;
      int x2 = b.first;
      int y1 = a.second;
      int y2 = b.second;
      int dx = x2 - x1;
      int dy = y2 - y1;
      int j = y1;
      int e = dy - dx;
  
      for(int i = x1; i &lt;= x2-1; i++){
          setPixel(i, j);
          if(e &gt;= 0){
              j++;
              e -= dx;
          }
          e += dy;
      }
  }
  </code></pre>
  <p>Here's my set pixel function. It assigns all 3 RGB values of the pixel in the .ppm file to black (0).</p>
  <pre class="lang-cpp prettyprint-override"><code>void setPixel(int x, int y){
      image[(x+(y*sizex))*3] = 0;
      image[(x+(y*sizex))*3+1] = 0;
      image[(x+(y*sizex))*3+2] = 0;
  }
  </code></pre>