Java interpolate interpolateColor(int rgba1, int rgba2, float percent)

Here you can find the source of interpolateColor(int rgba1, int rgba2, float percent)

Description

interpolate Color

License

Mozilla Public License

Declaration

public static int interpolateColor(int rgba1, int rgba2, float percent) 

Method Source Code

//package com.java2s;
//License from project: Mozilla Public License 

public class Main {
    public static int interpolateColor(int rgba1, int rgba2, float percent) {
        int r1 = rgba1 & 0xFF, g1 = rgba1 >> 8 & 0xFF, b1 = rgba1 >> 16 & 0xFF, a1 = rgba1 >> 24 & 0xFF;
        int r2 = rgba2 & 0xFF, g2 = rgba2 >> 8 & 0xFF, b2 = rgba2 >> 16 & 0xFF, a2 = rgba2 >> 24 & 0xFF;

        int r = (int) (r1 < r2 ? r1 + (r2 - r1) * percent : r2 + (r1 - r2) * percent);
        int g = (int) (g1 < g2 ? g1 + (g2 - g1) * percent : g2 + (g1 - g2) * percent);
        int b = (int) (b1 < b2 ? b1 + (b2 - b1) * percent : b2 + (b1 - b2) * percent);
        int a = (int) (a1 < a2 ? a1 + (a2 - a1) * percent : a2 + (a1 - a2) * percent);

        return r | g << 8 | b << 16 | a << 24;
    }//from   w  w  w. ja  v a2s . c  o m
}

Related

  1. interpolateBrightness(int a, int b, int c, int d)
  2. interpolateClamp(final double position, final double startPosition, final double endPosition, final double startValue, final double endValue)
  3. interpolateColor(double x, double y, int c0, int c1, int c2, int c3)
  4. interpolateColor(int a, int b, float w)
  5. interpolateColor(int c1, int c2, int st, int sts)
  6. interpolateColors(int a, int b, float lerp)
  7. interpolateColors(int c0, int c1, float w)
  8. interpolateCubic(int x0, int x1, int x2, int x3, double t)
  9. interpolatedNoise(int x, int z, int reciprocal)