Skip to content

Instantly share code, notes, and snippets.

@trystan
Created February 23, 2013 21:42
Show Gist options
  • Save trystan/5021485 to your computer and use it in GitHub Desktop.
Save trystan/5021485 to your computer and use it in GitHub Desktop.
RGB and HSV color in ActionScript
package
{
public class Color
{
public static function hsv(h:Number, s:Number, v:Number):uint
{
var r:Number, g:Number, b:Number, i:Number, f:Number, p:Number, q:Number, t:Number;
h %= 360;
if (v == 0)
return rgb(0, 0, 0);
s /= 100;
v /= 100;
h /= 60;
i = Math.floor(h);
f = h - i;
p = v * (1 - s);
q = v * (1 - (s * f));
t = v * (1 - (s * (1 - f)));
switch (i)
{
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
case 5: r = v; g = p; b = q; break;
}
return rgb(Math.floor(r*255), Math.floor(g*255), Math.floor(b*255));
}
public static function rgb (r:int, g:int, b:int):uint
{
return (255 << 24) | (r << 16) | (g << 8) | b;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment