title: HSV to RGB Stops at yellow C#
body: <p>I'm writing an HSVtoRGB method for my game framework, and when going through the hues, this happens -> <a href="http://youtu.be/ACBwR_0iMWE" rel="nofollow">http://youtu.be/ACBwR_0iMWE</a>.</p>
  
  <p>Here is the code.</p>
  
  <pre><code>public static Color HSVtoRGB(float hue, float saturation, float value, float alpha)
      {
          if(hue &gt; 1 || saturation &gt; 1  || value &gt; 1) throw new Exception("values cannot be more than 1!");
          if (hue &lt; 0 || saturation &lt; 0|| value &lt; 0) throw new Exception("values cannot be less than 0!");
  
          Color output = new Color();
          if (Math.Abs(saturation) &lt; 0.001)
          {
              output.R = (byte) (value*byte.MaxValue);
              output.G = (byte) (value*byte.MaxValue);
              output.B = (byte) (value*byte.MaxValue);
          }
          else
          {
              hue = hue/60f;
              float f = hue - (int)hue;
              float p = value*(1f - saturation);
              float q = value*(1f - saturation*f);
              float t = value*(1f - saturation*(1f - f));
              switch ((int)hue)
              {
                  case (0) :
                      output = new Color(value * 255, t * 255, p * 255, alpha);
                      break;
                  case (1):
                      output = new Color(q * 255, value * 255, p * 255, alpha);
                      break;
                  case (2):
                      output = new Color(p * 255, value * 255, t * 255, alpha);
                      break;
                  case (3):
                      output = new Color(p * 255, q * 255, value * 255, alpha);
                      break;
                  case (4):
                      output = new Color(t * 255, p * 255, value * 255, alpha);
                      break;
                  case (5):
                      output = new Color(value * 255, p * 255, q * 255, alpha);
                      break;
                  default :
                      throw new Exception("RGB color unknown!");
              }
  
          }
          return output;
      }
  </code></pre>
  
  <p>When adding <code>.001f</code> to the hue, it cause it to go from red to yellow but then sticks at yellow until it rolls back over to 0. Please note I am using <code>Microsoft.Xna.Framework.Color</code> not <code>System.Drawing.Color</code>.</p>
  
  <p>For reference, here is the HSVtoRGB method of <a href="http://www.photonstorm.com/flixel-power-tools" rel="nofollow">Flixel Power Tools</a>, basically what I am trying to copy.  </p>
  
  <pre><code>        public static function HSVtoRGB(h:Number, s:Number, v:Number, alpha:uint = 255):uint
      {
          var result:uint;
  
          if (s == 0.0)
          {
              result = getColor32(alpha, v * 255, v * 255, v * 255);
          }
          else
          {
              h = h / 60.0;
              var f:Number = h - int(h);
              var p:Number = v * (1.0 - s);
              var q:Number = v * (1.0 - s * f);
              var t:Number = v * (1.0 - s * (1.0 - f));
  
              switch (int(h))
              {
                  case 0:
                      result = getColor32(alpha, v * 255, t * 255, p * 255);
                      break;
  
                  case 1:
                      result = getColor32(alpha, q * 255, v * 255, p * 255);
                      break;
  
                  case 2:
                      result = getColor32(alpha, p * 255, v * 255, t * 255);
                      break;
  
                  case 3:
                      result = getColor32(alpha, p * 255, q * 255, v * 255);
                      break;
  
                  case 4:
                      result = getColor32(alpha, t * 255, p * 255, v * 255);
                      break;
  
                  case 5:
                      result = getColor32(alpha, v * 255, p * 255, q * 255);
                      break;
  
                  default:
                      FlxG.log("FlxColor Error: HSVtoRGB : Unknown color");
              }
          }
  
          return result;
      }
  </code></pre>