Java Color Interpolate interpolate(final Color aBaseColor, final Color aSecondaryColor, final float aDelta)

Here you can find the source of interpolate(final Color aBaseColor, final Color aSecondaryColor, final float aDelta)

Description

Interpolates a gray-scale color between two given colors.

License

Open Source License

Parameter

Parameter Description
aBaseColor a parameter
aSecondaryColor a parameter
aDelta a parameter

Declaration

public static Color interpolate(final Color aBaseColor, final Color aSecondaryColor, final float aDelta) 

Method Source Code


//package com.java2s;
/*//from  w  ww  . ja va 2s .  c om
 * OpenBench LogicSniffer / SUMP project 
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * Copyright (C) 2010-2011 - J.W. Janssen, <http://www.lxtreme.nl>
 */

import java.awt.*;

public class Main {
    /**
     * Interpolates a gray-scale color between two given colors.
     * 
     * @param aBaseColor
     * @param aSecondaryColor
     * @param aDelta
     * @return
     */
    public static Color interpolate(final Color aBaseColor, final Color aSecondaryColor, final float aDelta) {
        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]);
    }
}

Related

  1. interpolate(Color colour1, Color colour2, float colour2Fraction)
  2. interpolate(Color low, Color high, double min, double max, double v)
  3. interpolate(Color start, Color end, float p)
  4. interpolate(double factor, Color bottomCol, Color topCol)
  5. interpolate(double x, double y, float[] colorLL, float[] colorLR, float[] colorUL, float[] colorUR)
  6. interpolate(final Color from, final Color to, final double t)
  7. interpolate(java.awt.Color a, java.awt.Color b, float portion)
  8. interpolate2Color(final Color first, final Color second, float fraction)
  9. interpolateColor(Color color0, Color color1, double mixer, boolean useHue)