title: Trying to convert Integer range to RGB color
body: <p>I know you guys are all very busy, so I'm gonna keep it short and to the point. </p>
  
  <p>I'm currently developing a little game for fun. There's enemys in the game. For simplicity, think about them as colored squares. I want to minimize any HUD, so I decided to display the hit points of the creatures smoothly via their color 
  (green for healthy, yellow for damaged, red for nearly dead). </p>
  
  <p>See image :
  <a href="https://i.stack.imgur.com/slSB2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/slSB2.png" alt="enter image description here"></a></p>
  
  <p>I however really struggle to come up with a decently efficient method that converts an (int) hp-value to an RGB-color. Mapping to a single int from 0-255 would not be a problem at all - here's an example function that does exactly that: </p>
  
  <pre><code>public int mapHpToGreyscale(int input) {
  
      //input = current hp
      double minHealth = 0;
      double maxHealth = hpmax;
      double minColValue = 0;
      double maxColValue = 255;
  
      int output = (int) ((input - minHealth) / (maxHealth - minHealth) * (maxColValue - minColValue) + minColValue);
  
      return output;
  }
  </code></pre>
  
  <p>Is there a quick and easy way to achieve what I want to do? I'd appreciate any input.</p>