Java Color Mix mix(Color a, Color b, double percent)

Here you can find the source of mix(Color a, Color b, double percent)

Description

Mixes two colours.

License

Open Source License

Parameter

Parameter Description
a Base colour.
b Colour to mix in.
percent Percentage of the old colour to keep around.

Return

the mixed Color

Declaration

public static Color mix(Color a, Color b, double percent) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;

public class Main {
    /**/*from w ww  . ja va2s  .  c  o m*/
     * Mixes two colours.
     *
     * @param a       Base colour.
     * @param b       Colour to mix in.
     * @param percent Percentage of the old colour to keep around.
     * @return the mixed Color
     */
    public static Color mix(Color a, Color b, double percent) {
        return new Color((int) (a.getRed() * percent + b.getRed() * (1.0 - percent)),
                (int) (a.getGreen() * percent + b.getGreen() * (1.0 - percent)),
                (int) (a.getBlue() * percent + b.getBlue() * (1.0 - percent)));
    }
}

Related

  1. mix(Color c0, Color c1, float amount)
  2. mix(Color c1, Color c2)
  3. mix(Color c1, Color c2)
  4. mix(Color c1, Color c2, boolean useAlpha)