title: Get Color From HSL Values in Flash
body: <p>I just want to know how to get a Color() Object or a Hex Color Value ( uint ) from HSL values in flash.´</p>
  
  <p>The idea behind the HSL is, that i can map vaues from a range ob anything, to the range of the Hue ( 0 - 360 ) and get the coresponding color.</p>
  
  <p>Further I want to control the Hue value seperate from the "lightness" or "brightness" value.
  the saturation will allways be 100%.</p>
  
  <p>The "base" of my code looks like this:</p>
  
  <pre><code>function getHSL( var Hue, var Saturation, var Lightness ) {
  // Hue = 0 - 360, Satturation = 0 - 100, Lightness = 0 - 100
  
      // DO THE MAGIC
  
      return color // as3 Color() object
  }
  </code></pre>
  
  <p>So if I would have this funktion, i could just call it in a <code>for( i=0; i&lt;360; i++)</code> loop where <code>i</code> would be the Hue to create a rainbow color spectrum.</p>
  
  <p>i already have done some <code>map()</code> functions to easily handle "streching" color spectrums ( like bars that are not exactly 360 px long.</p>
  
  <p>So guys if you have any idea how i could generate Colors from HSL values in as3, please tell me.</p>
  
  <p><strong>SOLUTION UPDATE</strong></p>
  
  <pre><code>function getColorFromHSL( h:Number, s:Number, v:Number ):Array {
      var r:Number = 0;
      var g:Number = 0;
      var b:Number = 0;
      var rgb:Array = [];
  
      var tempS:Number = s / 100;
      var tempV:Number = v / 100;
  
      var hi:int = Math.floor(h/60) % 6;
      var f:Number = h/60 - Math.floor(h/60);
      var p:Number = (tempV * (1 - tempS));
      var q:Number = (tempV * (1 - f * tempS));
      var t:Number = (tempV * (1 - (1 - f) * tempS));
  
      switch(hi)
      {
          case 0: r = tempV; g = t; b = p; break;
          case 1: r = q; g = tempV; b = p; break;
          case 2: r = p; g = tempV; b = t; break;
          case 3: r = p; g = q; b = tempV; break;
          case 4: r = t; g = p; b = tempV; break;
          case 5: r = tempV; g = p; b = q; break;
      }
  
      rgb = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
      return rgb;
  }
  </code></pre>