Java Lerp lerp(final double percent, final int startColor, final int endColor)

Here you can find the source of lerp(final double percent, final int startColor, final int endColor)

Description

lerp

License

Open Source License

Declaration

public static int lerp(final double percent, final int startColor, final int endColor) 

Method Source Code

//package com.java2s;
/**/* w  w  w .  j  a va2s  .  c o  m*/
 * Copyright (c) 2008-2012 Ardor Labs, Inc.
 *
 * This file is part of Ardor3D.
 *
 * Ardor3D is free software: you can redistribute it and/or modify it 
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or at <http://www.ardor3d.com/LICENSE>.
 */

public class Main {
    public static int lerp(final double percent, final int startColor, final int endColor) {
        if (startColor == endColor) {
            return startColor;
        } else if (percent <= 0.0) {
            return startColor;
        } else if (percent >= 1.0) {
            return endColor;
        }

        final int r = (int) ((1.0 - percent) * (startColor >> 24 & 0xFF) + percent * (endColor >> 24 & 0xFF));
        final int g = (int) ((1.0 - percent) * (startColor >> 16 & 0xFF) + percent * (endColor >> 16 & 0xFF));
        final int b = (int) ((1.0 - percent) * (startColor >> 8 & 0xFF) + percent * (endColor >> 8 & 0xFF));
        final int a = (int) ((1.0 - percent) * (startColor & 0xFF) + percent * (endColor & 0xFF));

        return r << 24 | g << 16 | b << 8 | a;
    }
}

Related

  1. lerp(double start, double distance, double factor)
  2. lerp(double v1, double v2, double amt)
  3. lerp(double x, double x1, double x2, double q00, double q01)
  4. lerp(double x, double x1, double x2, double q00, double q01)
  5. lerp(final double a, final double min, final double max)
  6. lerp(final float a, final float b, final float f)
  7. lerp(final float percent, final float startValue, final float endValue)
  8. lerp(final float x, final float x1, final float x2, final float q00, final float q01)
  9. lerp(float a, float b, float f)