From c6d3fc8907b8b0e6e203fd9d3fc6a00078c823b0 Mon Sep 17 00:00:00 2001 From: kascade Date: Fri, 21 Jul 2006 11:40:27 +0000 Subject: [PATCH] color scaler utility class added for determining color based on a scale from 0 to 1 git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@162 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d --- src/enginuity/util/ColorScaler.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/enginuity/util/ColorScaler.java diff --git a/src/enginuity/util/ColorScaler.java b/src/enginuity/util/ColorScaler.java new file mode 100644 index 00000000..94fb4a4e --- /dev/null +++ b/src/enginuity/util/ColorScaler.java @@ -0,0 +1,26 @@ +package enginuity.util; + +import java.awt.*; + +public final class ColorScaler { + private static final int MAX_COLOR_INTENSITY = 200; + + private ColorScaler() { + } + + public static Color getScaledColor(double scale) { + int r = (int) ((Math.cos(Math.toRadians(180 + scale * 180)) + 1) * MAX_COLOR_INTENSITY / 2) + 30; + int g = (int) ((Math.cos(Math.toRadians(180 + scale * 360)) + 1) * MAX_COLOR_INTENSITY / 2) + 60; + int b = (int) ((Math.cos(Math.toRadians(scale * 180)) + 1) * MAX_COLOR_INTENSITY / 2) + 20; + + if (r > MAX_COLOR_INTENSITY) r = MAX_COLOR_INTENSITY; + if (g > MAX_COLOR_INTENSITY) g = MAX_COLOR_INTENSITY; + if (b > MAX_COLOR_INTENSITY) b = MAX_COLOR_INTENSITY; + + if (r < 0) r = 0; + if (g < 0) g = 0; + if (b < 0) b = 0; + + return new Color(r, g, b); + } +}