title: PHP Red to Green RGB Color Heatmap
body: <p>I can't seem to get this figured out.  I have a scaled set of values (0...1) that I need to associate colors with.  The highest (1) being red and the lowest (0) being green.</p>
  
  <p>I cannot seem to find how to get an RGB color between red and green for a value that is between 0 and 1.</p>
  
  <p>Here is my scaling function I am going to use to scale the values:</p>
  
  <pre><code>function scale_value($value, $srcmin, $srcmax, $destmin = 0, $destmax = 1)
  {
      # How Far In Source Range Are We
      $pos = (($value - $srcmin) / ($srcmax - $srcmin));
      return ($pos * ($destmax - $destmin)) + $destmin;
  }
  </code></pre>
  
  <p>I figured scaling them from 0 to 1 will make the next part I am struggling with much easier.</p>
  
  <p>Here is one very crummy attempt at doing this I came up with, failed pretty badly.</p>
  
  <pre><code>function make_color($value)
  {
      $red = $value &gt; 0.5
         ? (1 - 2 * ($value - 0.5) / 1)
         : 1;
      $green = $value &gt; 0.5
          ? 1
          : 2 * ($value / 1);
      $blue = 0;
      return "rgb($red,$green,$blue)";
  }
  </code></pre>
  
  <p>Does anyone have any experience using PHP to determine the color to use for a value that falls between 1 and 0?</p>