title: Draw a line from start(X,Y) to destination(X,Y)
body: <p>I'm struggling to make a simple game with an world map on which the player will move around, using a click-and-go-along-a-line method. For this I'm trying to make a simple function to calculate a list of XY of pixels for the player to go through.</p>
  
  <p>Most of it works fine, but I'm having issues with it multiplying one of the results by 2 whenever destination X and Y are not equal. I'm having a really tough time troubleshooting this one, and if somebody would have an idea how to improve it or fix it - I'd be very grateful.</p>
  
  <pre><code>import math
  
  def linePath(start, finish):
      if start[0] == finish[0]:
          a = 1
      else:
          a = (finish[1] - start[1]) / float((finish[0] - start[0]))
      b = start[1] - (a * start[0])
      if abs(a) &gt;= 1:
          rng = xrange(start[1], finish[1] + 1) or reversed(xrange(finish[1], start[1] + 1))
      else:
          rng = xrange(start[0], finish[0] + 1) or reversed(xrange(finish[0], start[0] + 1))
      for i in rng:
          if abs(a) &gt;= 1:
              y = i
              x = int(math.ceil((y - b)/ a))
          else:
              x, y = i, start[1] + int(math.ceil(a * i + b))
          if start[0] != finish[0]:
              yield x, y
          else:
              yield start[0], y
  
  start = (10, 10)
  destination = (15, 15)
  
  print list(linePath(start, destination))
  
  #Bugs:   when start[0] &gt; start[1] and start &gt; destination (eg. destination = (16, 15))
          #when start[0] &lt; start[1] and start &lt; destination (eg. destination = (5, 6))
  </code></pre>