List of utility methods to do Color Interpolate
Color | interpolate(Color a, Color b, float f) interpolate float rf = 1 - f; int red = (int) (a.getRed() * rf + b.getRed() * f); int green = (int) (a.getGreen() * rf + b.getGreen() * f); int blue = (int) (a.getBlue() * rf + b.getBlue() * f); int alpha = (int) (a.getAlpha() * rf + b.getAlpha() * f); return new Color(red, green, blue, alpha); |
Color | interpolate(Color b, Color a, float t) interpolate float[] acomp = a.getRGBComponents(null); float[] bcomp = b.getRGBComponents(null); float[] ccomp = new float[4]; for (int i = 0; i < 4; i++) { ccomp[i] = acomp[i] + (bcomp[i] - acomp[i]) * t; return new Color(ccomp[0], ccomp[1], ccomp[2], ccomp[3]); |
Color | interpolate(Color c1, Color c2, float fracFromC1) Linearly interpolates between two RGB colours float fracFromC2 = 1.0f - fracFromC1; return new Color(Math.round(fracFromC1 * c1.getRed() + fracFromC2 * c2.getRed()), Math.round(fracFromC1 * c1.getGreen() + fracFromC2 * c2.getGreen()), Math.round(fracFromC1 * c1.getBlue() + fracFromC2 * c2.getBlue()), Math.round(fracFromC1 * c1.getAlpha() + fracFromC2 * c2.getAlpha())); |
Color | interpolate(Color colour1, Color colour2, float colour2Fraction) interpolate float[] hsb1 = new float[3]; Color.RGBtoHSB(colour1.getRed(), colour1.getGreen(), colour1.getBlue(), hsb1); float[] hsb2 = new float[3]; Color.RGBtoHSB(colour2.getRed(), colour2.getGreen(), colour2.getBlue(), hsb2); float h = hsb1[0] + (float) colour2Fraction * (hsb2[0] - hsb1[0]); float s = hsb1[1] + (float) colour2Fraction * (hsb2[1] - hsb1[1]); float b = hsb1[2] + (float) colour2Fraction * (hsb2[2] - hsb1[2]); return Color.getHSBColor(h, s, b); ... |
Color | interpolate(Color low, Color high, double min, double max, double v) Linear interpolation between two colors. if (v > max) { v = max; if (v < min) { v = min; double distance = 1 - ((max - v) / (max - min)); if (Double.isNaN(distance) || Double.isInfinite(distance)) { ... |
Color | interpolate(Color start, Color end, float p) interpolate float[] startHSB = Color.RGBtoHSB(start.getRed(), start.getGreen(), start.getBlue(), null); float[] endHSB = Color.RGBtoHSB(end.getRed(), end.getGreen(), end.getBlue(), null); float brightness = (startHSB[2] + endHSB[2]) / 2; float saturation = (startHSB[1] + endHSB[1]) / 2; float hueMax = 0; float hueMin = 0; if (startHSB[0] > endHSB[0]) { hueMax = startHSB[0]; ... |
String | interpolate(double factor, Color bottomCol, Color topCol) interpolate int red, blue, green; red = (int) Math.round((1.0 - factor) * bottomCol.getRed() + factor * topCol.getRed()); blue = (int) Math.round((1.0 - factor) * bottomCol.getBlue() + factor * topCol.getBlue()); green = (int) Math.round((1.0 - factor) * bottomCol.getGreen() + factor * topCol.getGreen()); Color color = new Color(Math.min(red, 255), Math.min(green, 255), Math.min(blue, 255)); return Integer.toHexString(color.getRGB()).substring(2, 8); |
Color | interpolate(double x, double y, float[] colorLL, float[] colorLR, float[] colorUL, float[] colorUR) Interpolate among 4 colors (corresponding to the 4 points on a square) float[] rgbaL = new float[4]; float[] rgbaU = new float[4]; rgbaL[0] = (float) (colorLL[0] + x * (colorLR[0] - colorLL[0])); rgbaL[1] = (float) (colorLL[1] + x * (colorLR[1] - colorLL[1])); rgbaL[2] = (float) (colorLL[2] + x * (colorLR[2] - colorLL[2])); rgbaL[3] = (float) (colorLL[3] + x * (colorLR[3] - colorLL[3])); rgbaU[0] = (float) (colorUL[0] + x * (colorUR[0] - colorUL[0])); rgbaU[1] = (float) (colorUL[1] + x * (colorUR[1] - colorUL[1])); ... |
Color | interpolate(final Color aBaseColor, final Color aSecondaryColor, final float aDelta) Interpolates a gray-scale color between two given colors. float[] acomp = aSecondaryColor.getRGBComponents(null); float[] bcomp = aBaseColor.getRGBComponents(null); float[] ccomp = new float[4]; for (int i = 0; i < 4; i++) { ccomp[i] = acomp[i] + ((bcomp[i] - acomp[i]) * aDelta); return new Color(ccomp[0], ccomp[1], ccomp[2], ccomp[3]); |
Color | interpolate(final Color from, final Color to, final double t) Interpolates between two colors. if (Double.isNaN(t)) throw new IllegalArgumentException("NaN"); if (t > 1 || t < 0) throw new IllegalArgumentException("" + t); final float[] fromRGBA = new float[4]; final float[] toRGBA = new float[4]; from.getRGBComponents(fromRGBA); to.getRGBComponents(toRGBA); ... |