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
This commit is contained in:
kascade 2006-07-21 11:40:27 +00:00
parent 799990e270
commit c6d3fc8907
1 changed files with 26 additions and 0 deletions

View File

@ -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);
}
}