Java Color Mix mixColors(Color a, Color b, double r)

Here you can find the source of mixColors(Color a, Color b, double r)

Description

mix Colors

License

Open Source License

Declaration

public static Color mixColors(Color a, Color b, double r) 

Method Source Code


//package com.java2s;
// modify it under the terms of the GNU General Public License

import java.awt.Color;

public class Main {
    public static Color mixColors(Color a, Color b, double r) {
        double s = 1.0f - r;
        return new Color(boundColor((a.getRed() * r + b.getRed() * s) / 255.0),
                boundColor((a.getGreen() * r + b.getGreen() * s) / 255.0),
                boundColor((a.getBlue() * r + b.getBlue() * s) / 255.0));
    }/*from w  ww. j av a2 s  .c o m*/

    private static float boundColor(double c) {
        if (!(c > 0))
            return 0;
        if (c > 1.0)
            return 1.0f;
        return (float) c;
    }
}

Related

  1. mix(Color src, Color dst, double factor)
  2. mix(double x, double y, double a)
  3. mix(final Color c1, final Color c2, final double factor)
  4. mix(int a, int b, int amt)
  5. mixColor(Paint p, double value)
  6. mixColors(Color c)
  7. mixColors(List colors)
  8. mixColorWithAlpha(Color base, Color mix)
  9. mixedColor(Color originalColor, Color overlayColor)