Returns an interpoloated color, between a and b - Android Graphics

Android examples for Graphics:Color Value

Description

Returns an interpoloated color, between a and b

Demo Code

/*// ww w .j  a  v  a  2 s.com

    Copyright 2013, 2014 joshua.tee@gmail.com

    This file is part of wX.

    wX 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 3 of the License, or
    (at your option) any later version.

    wX 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 wX.  If not, see <http://www.gnu.org/licenses/>.

 */
//package com.java2s;
import android.graphics.Color;

public class Main {
    /** Returns an interpoloated color, between <code>a</code> and <code>b</code> */
    public static int interpolateColor(Integer a, Integer b,
            Double proportion) {
        float[] hsva = new float[3];
        float[] hsvb = new float[3];
        Color.colorToHSV(a, hsva);
        Color.colorToHSV(b, hsvb);
        for (int i = 0; i < 3; i++) {
            hsvb[i] = interpolate(hsva[i], hsvb[i], new Float(proportion));
        }
        return Color.HSVToColor(hsvb);
    }

    public static float interpolate(float a, float b, float proportion) {
        return (a + ((b - a) * proportion));
    }
}

Related Tutorials