From d22350ff3caa321e98e257771e1fea20aa6fb53a Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 18 Jul 2002 23:14:02 +0000 Subject: [PATCH] Added a version of blend that takes a float argument so that two colors may be blended at a ratio other than 50-50. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1593 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/media/image/ColorUtil.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/media/image/ColorUtil.java b/src/java/com/threerings/media/image/ColorUtil.java index 5d1045458..05860bfeb 100644 --- a/src/java/com/threerings/media/image/ColorUtil.java +++ b/src/java/com/threerings/media/image/ColorUtil.java @@ -1,5 +1,5 @@ // -// $Id: ColorUtil.java,v 1.2 2002/03/26 23:35:01 ray Exp $ +// $Id: ColorUtil.java,v 1.3 2002/07/18 23:14:02 ray Exp $ package com.threerings.media.util; @@ -21,4 +21,19 @@ public class ColorUtil (c1.getGreen() + c2.getGreen()) >> 1, (c1.getBlue() + c2.getBlue()) >> 1); } + + /** + * Blends the two supplied colors, using the supplied percentage + * as the amount of the first color to use. + * + * @param firstperc The percentage of the first color to use, from 0.0f + * to 1.0f inclusive. + */ + public static final Color blend (Color c1, Color c2, float firstperc) + { + float p2 = 1.0f - firstperc; + return new Color((int) (c1.getRed() * firstperc + c2.getRed() * p2), + (int) (c1.getGreen() * firstperc + c2.getGreen() * p2), + (int) (c1.getBlue() * firstperc + c2.getBlue() * p2)); + } }