From c0b89ae7a5f3799191c58f396168d24b2147dbde Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 12 Dec 2006 23:09:38 +0000 Subject: [PATCH] ColorUtil. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4480 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/ColorUtil.as | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/as/com/threerings/util/ColorUtil.as diff --git a/src/as/com/threerings/util/ColorUtil.as b/src/as/com/threerings/util/ColorUtil.as new file mode 100644 index 000000000..fc3a0e322 --- /dev/null +++ b/src/as/com/threerings/util/ColorUtil.as @@ -0,0 +1,31 @@ +// +// $Id$ + +package com.threerings.util { + +/** + * Color utility methods. + * + * See also mx.utils.ColorUtil. + */ +public class ColorUtil +{ + /** + * Blend the two colors, either 50-50 or according to the ratio specified. + */ + public static function blend ( + first :uint, second :uint, firstPerc :Number = 0.5) :uint + { + var secondPerc :Number = 1 - firstPerc; + + var result :uint = 0; + for (var shift :int = 0; shift <= 16; shift += 8) { + var c1 :uint = (first >> shift) & 0xFF; + var c2 :uint = (second >> shift) & 0xFF; + result |= uint(Math.max(0, Math.min(255, + (c1 * firstPerc) + (c2 * secondPerc)))) << shift; + } + return result; + } +} +}