title: Movement algorithm with friction
body: <p>For example, I have an object that follows mouse horizontally, its minimum position is 100 and the maximum is 200.</p>
  
  <p>Within this range, it follows mouse linearly, meaning 1 unit of mouse position equals to 1 unit of object position.</p>
  
  <p>Now, if the mouse is outside of the range (below 100, or above 200), I want it to start applying friction, so the object gracefully stops the further it is from range, for example:</p>
  
  <pre><code>Mouse position  | Object position
  200               200
  220               205
  240               209
  260               212
  280               215
  300               217
  320               218
  340               219
  360               220
  380               220
  400               220
  ...
  </code></pre>
  
  <p>I managed to implement it like this within mouse-move handler:</p>
  
  <pre><code>if (mousePosition &gt; 200 || mousePosition &lt; 100) {
    delta = mousePosition - objectPosition;
    objectPosition += delta * 0.25; // 0.25 if friction factor
  }
  </code></pre>
  
  <p>But is there a better way? How to implement function outside of mouse-move handler:</p>
  
  <pre><code>getObjectPosition(mousePosition) {
    return // ???
  }
  </code></pre>
  
  <p>The question is language agnostic.</p>