title: Linear Gradient between two points
body: <p>I'm trying to generate a linear gradient on my pixel raster. I do this in processing 2.0 - this is mainly Java but with some extra classes and variables. I already have a function to do a radial gradient:</p>
  
  <pre><code>/* For every pixel */
    distance = dist(centerX,centerY, x,y); //calculate distance between position and center of gradient
    lerpValue = norm(distance, 0, maxRadius) //normalize this value between 0 and the give maximum radius
    color = lerpColor(startColor, endColor, lerpValue ); //calculate Color
  /*end for*/
  </code></pre>
  
  <p>This was easier than I thought. Then I tried to do a gradient from one point to another, and I can't figure out how to calculate this. Of course a horizontal or vertical gradient is no problem, but within two points the line could be any angle. 
  I already found an answer to a similar question but actually I didn't understand it. Would someone explain to me how this calculation is possible - with description in easy words? Please explain what your're doing because I want to understand it and not just copy it. And if you write code please give the variables good names. I know it's faster to write single character names but I don't always know what exactly they are. 
  Oh and the calculation should be pixel per pixel, because rotating lines and drawing them every x steps is pretty slow I think and can lead to ugly results (wrong colors with antialiasing, stairs without).
  I hope I don't ask too much but as I said I really want to understand how this works, and that's pretty hard if i have to guess e.g. what the names of variables mean.. </p>