title: How to add Hue to a given color programmatically?
body: <p>I tried to implement a my color editor in Java. It should be a simple software. The user will input color in hexadecimal RGBs, for example: 0xFF00FF. I know how to calculate Hue, Chroma, Saturation and Lightness, but how to add or substract Hue value to this given color? This is the mystery.</p>
  
  <p>Is there any algorithm or formula to use? </p>
  
  <p>Now I use this method, but I think the result is different from what I got with Adobe Photoshop.</p>
  
  <pre><code>public void addHue(float addHue) {
      float c = getChroma();
      addHue %= 6;
      if (addHue &lt; 2) {
          float n = 1 - green;
          green = green + addHue * n;
      } else if (addHue &lt; 4) {
          addHue -= 2;
          float n = 1 - blue;
          blue = blue + addHue * n;
      } else if (addHue &lt; 6) {
          addHue -=4;
          float n = 1 - red;
          red = red + addHue * n;
      }
      if (green &gt; 1) green = 1;
      else if (green &lt; 0) green = 0;
      if (red &gt; 1) red = 1;
      else if (red &lt; 0) red = 0;
      if (blue &gt; 1) blue = 1;
      else if (blue &lt; 0) blue = 0;
  }
  </code></pre>