title: Suggested algorithm for diverging color mapping visualization
body: <p>I am attempting to write a piece of code that is suppose to map data to RGB values, and one of the types of visualizations I am attempting to use is a diverging color map.</p>
  
  <p>I am not exactly sure what the best way is to go about applying the colors. The current algorithm I am using is:
          //F is the data point being checked</p>
  
  <pre><code>if(F &lt;= .5){
      RGB[0] = F*510;
      RGB[1] = F*510;
      RGB[2] = F*254 + 128;
  }else{
      RGB[0] = 255 - (F-.5)*254;
      RGB[1] = 255 - (F-.5)*510;
      RGB[2] = 255 - (F-.5)*510;  
  }
  </code></pre>
  
  <p>Where the key points for the curve are:</p>
  
  <pre><code>      F=0: (0,0,128) 
        F=0.5: (255,255,255) 
        F=1: (128, 0, 0)
  </code></pre>
  
  <p>Are there any suggested algorithms out there for use instead of this, or is this hacked together piecewise function alright?
  This is the image generated by this current algorithm.
  <img src="https://i.stack.imgur.com/VwrvY.png" alt="Color Curve: Divergent"></p>