Java Utililty Methods Color Mix

List of utility methods to do Color Mix

Description

The list of methods to do Color Mix are organized into topic(s).

Method

Colormix(Color a, Color b, double percent)
Mixes two colours.
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)));
Colormix(Color c0, Color c1, float amount)
Mixes two colors.
float r0 = c0.getRed() / 255f;
float g0 = c0.getGreen() / 255f;
float b0 = c0.getBlue() / 255f;
float a0 = c0.getAlpha() / 255f;
float r1 = c1.getRed() / 255f;
float g1 = c1.getGreen() / 255f;
float b1 = c1.getBlue() / 255f;
float a1 = c1.getAlpha() / 255f;
...
Colormix(Color c1, Color c2)
mix
return new Color((c1.getRed() + c2.getRed()) / 2, (c1.getGreen() + c2.getGreen()) / 2,
        (c1.getBlue() + c2.getBlue()) / 2);
Colormix(Color c1, Color c2)
Mix colors visually: red + green = yellow, etc.
final float[] b = Color.RGBtoHSB(c1.getRed(), c1.getGreen(), c1.getBlue(), new float[3]);
final float[] c = Color.RGBtoHSB(c2.getRed(), c2.getGreen(), c2.getBlue(), new float[3]);
final float[] a = new float[3];
float h1 = b[0];
float h2 = c[0];
if (h1 < h2) {
    float tmp = h1;
    h1 = h2;
...
Colormix(Color c1, Color c2, boolean useAlpha)
Mix 2 colors without "priority" color
final int r, g, b, a;
if (useAlpha) {
    final float a1 = c1.getAlpha() / 255f;
    final float a2 = c2.getAlpha() / 255f;
    final float af = a1 + a2;
    r = (int) (((c1.getRed() * a1) + (c2.getRed() * a2)) / af);
    g = (int) (((c1.getGreen() * a1) + (c2.getGreen() * a2)) / af);
    b = (int) (((c1.getBlue() * a1) + (c2.getBlue() * a2)) / af);
...
Colormix(Color c1, Color c2, double f)
Mix two colors by a given amount
if (f >= 1.0)
    return c2;
if (f <= 0)
    return c1;
double r1 = c1.getRed();
double g1 = c1.getGreen();
double b1 = c1.getBlue();
double r2 = c2.getRed();
...
Colormix(Color c1, Color c2, float bias)
Mixes two given colors.
if (bias <= 0.0)
    return c1;
if (bias >= 1.0)
    return c2;
if (Double.isNaN(bias))
    return c1; 
float r = mixNumberFloat(c1.getRed() / 256f, c2.getRed() / 256f, bias);
float g = mixNumberFloat(c1.getGreen() / 256f, c2.getGreen() / 256f, bias);
...
Colormix(Color src, Color dst, double factor)
mix
double fs = factor / 255.0;
double fd = (1.0 - factor) / 255.0;
double r = src.getRed() * fs + dst.getRed() * fd;
double g = src.getGreen() * fs + dst.getGreen() * fd;
double b = src.getBlue() * fs + dst.getBlue() * fd;
int ir = Math.max(0, Math.min(255, (int) Math.round(r * 255)));
int ig = Math.max(0, Math.min(255, (int) Math.round(g * 255)));
int ib = Math.max(0, Math.min(255, (int) Math.round(b * 255)));
...
doublemix(double x, double y, double a)
mix
return x + a * (y - x);
Colormix(final Color c1, final Color c2, final double factor)
mix
assert 0 <= factor && factor <= 1.0 : factor;
final double backFactor = 1.0 - factor;
return new Color(Math.min((int) Math.round(c1.getRed() * backFactor + c2.getRed() * factor), 255),
        Math.min((int) Math.round(c1.getGreen() * backFactor + c2.getGreen() * factor), 255),
        Math.min((int) Math.round(c1.getBlue() * backFactor + c2.getBlue() * factor), 255));