Java Color Interpolate interpolate(double x, double y, float[] colorLL, float[] colorLR, float[] colorUL, float[] colorUR)

Here you can find the source of interpolate(double x, double y, float[] colorLL, float[] colorLR, float[] colorUL, float[] colorUR)

Description

Interpolate among 4 colors (corresponding to the 4 points on a square)

License

MIT License

Return

The interpolated color.

Declaration

public static Color interpolate(double x, double y, float[] colorLL, float[] colorLR, float[] colorUL,
        float[] colorUR) 

Method Source Code

//package com.java2s;
/** Copyright by Barry G. Becker, 2000-2011. Licensed under MIT License: http://www.opensource.org/licenses/MIT  */

import java.awt.Color;

public class Main {
    /**//  w  ww .j a v a2s  .  c  o m
     * Interpolate among 4 colors (corresponding to the 4 points on a square)
     * @return The interpolated color.
     */
    public static Color interpolate(double x, double y, float[] colorLL, float[] colorLR, float[] colorUL,
            float[] colorUR) {

        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]));
        rgbaU[2] = (float) (colorUL[2] + x * (colorUR[2] - colorUL[2]));
        rgbaU[3] = (float) (colorUL[3] + x * (colorUR[3] - colorUL[3]));

        return new Color((float) (rgbaL[0] + y * (rgbaU[0] - rgbaL[0])),
                (float) (rgbaL[1] + y * (rgbaU[1] - rgbaL[1])), (float) (rgbaL[2] + y * (rgbaU[2] - rgbaL[2])),
                (float) (rgbaL[3] + y * (rgbaU[3] - rgbaL[3])));
    }
}

Related

  1. interpolate(Color c1, Color c2, float fracFromC1)
  2. interpolate(Color colour1, Color colour2, float colour2Fraction)
  3. interpolate(Color low, Color high, double min, double max, double v)
  4. interpolate(Color start, Color end, float p)
  5. interpolate(double factor, Color bottomCol, Color topCol)
  6. interpolate(final Color aBaseColor, final Color aSecondaryColor, final float aDelta)
  7. interpolate(final Color from, final Color to, final double t)
  8. interpolate(java.awt.Color a, java.awt.Color b, float portion)
  9. interpolate2Color(final Color first, final Color second, float fraction)