From a4f52c995981095d52fb1f2e13c98734169ef6c0 Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Thu, 16 Apr 2009 19:17:08 +0000 Subject: [PATCH] ColorUtil.getHue() git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@808 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flash/ColorUtil.as | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/as/com/threerings/flash/ColorUtil.as b/src/as/com/threerings/flash/ColorUtil.as index 4b83b8da..967c52df 100644 --- a/src/as/com/threerings/flash/ColorUtil.as +++ b/src/as/com/threerings/flash/ColorUtil.as @@ -45,5 +45,22 @@ public class ColorUtil } return result; } + + /** + * Returns a color's Hue value, in degrees. 0<=Hue<=360. + * http://en.wikipedia.org/wiki/Hue + */ + public static function getHue (color :uint) :Number + { + var r :Number = (color >> 16) & 0xff; + var g :Number = (color >> 8) & 0xff; + var b :Number = color & 0xff; + + var hue :Number = R2D * Math.atan2(ROOT_3 * (g - b), 2 * (r - g - b)); + return (hue >= 0 ? hue : hue + 360); + } + + protected static const ROOT_3 :Number = Math.sqrt(3); + protected static const R2D :Number = 180 / Math.PI; // radians to degrees } }