Interpolate a color at a given fraction between 0 and 1.

@param color1 start color.
@param color2 end color.
@param fraction the fraction to interpolate.
@return the new color.
16547
public static Color interpolateColor( Color color1, Color color2, float fraction ) {
        float int2Float = 1f / 255f;
        fraction = Math.min(fraction, 1f);
        fraction = Math.max(fraction, 0f);

        float r1 = color1.getRed() * int2Float;
        float g1 = color1.getGreen() * int2Float;
        float b1 = color1.getBlue() * int2Float;
        float a1 = color1.getAlpha() * int2Float;

        float r2 = color2.getRed() * int2Float;
        float g2 = color2.getGreen() * int2Float;
        float b2 = color2.getBlue() * int2Float;
        float a2 = color2.getAlpha() * int2Float;

        float deltaR = r2 - r1;
        float deltaG = g2 - g1;
        float deltaB = b2 - b1;
        float deltaA = a2 - a1;

        float red = r1 + (deltaR * fraction);
        float green = g1 + (deltaG * fraction);
        float blue = b1 + (deltaB * fraction);
        float alpha = a1 + (deltaA * fraction);

        red = Math.min(red, 1f);
        red = Math.max(red, 0f);
        green = Math.min(green, 1f);
        green = Math.max(green, 0f);
        blue = Math.min(blue, 1f);
        blue = Math.max(blue, 0f);
        alpha = Math.min(alpha, 1f);
        alpha = Math.max(alpha, 0f);

        return new Color(red, green, blue, alpha);
    }
350219
@Override
	public Color put(Double position, Color color) {
		if( position == null ) {
			throw new NullPointerException("Null endpoint position");
		}
		if( color == null ){
			throw new NullPointerException("Null colors are not allowed.");
		}
		return mapping.put(position, color);
	}
805609
@ColorInt
    public static int getAlphaColor(@ColorInt int color, @IntRange(from = 0, to = 255) int alpha) {
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        return Color.argb(alpha, red, green, blue);
    }
340529
def interpolate_color(c1, c2, factor: float) -> list:
    
    assert(len(c1) == len(c2))

    new_color = []
    for i in range(len(c1)):
        new_color.append(int(interpolate(c1[i], c2[i], factor)))
    return new_color
64370
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
  }
758395
function(color1, color2) {
		var result = color1.slice();
		for (var i=0;i<3;i++) {
			for (var j=1;j<arguments.length;j++) {
				result[i] += arguments[j][i];
			}
		}
		return result;
	}
1086483
private int getColor(int value) {
		if (value == 0) {
			return 0;
		}

		double scale = Math.log10(value) / Math.log10(this.topValue);
		double lengthScale = Math.min(1.0, scale) * (colors.length - 1);
		int index = 1 + (int) lengthScale;
		if (index == colors.length) {
			index--;
		}
		double partScale = lengthScale - (index - 1);

		int r = (int) (colors[index - 1][0] + partScale
				* (colors[index][0] - colors[index - 1][0]));
		int g = (int) (colors[index - 1][1] + partScale
				* (colors[index][1] - colors[index - 1][1]));
		int b = (int) (colors[index - 1][2] + partScale
				* (colors[index][2] - colors[index - 1][2]));

		r = Math.min(255, r);
		b = Math.min(255, b);
		g = Math.min(255, g);
		return (r << 16) | (g << 8) | b;
	}
545339
function _generateInterpolatedColor() {
  const randIndicies = _getNextColorPair();
  const fraction = Math.random();
  const interpolatedColor = [];

  for (let i = 0; i < 4; i++) {
    interpolatedColor.push(
      Math.floor(
        fraction * distinctColors[randIndicies[0]][i] +
          (1.0 - fraction) * distinctColors[randIndicies[1]][i]
      )
    );
  }

  return interpolatedColor;
}
289003
public DoublePoint Divide(DoublePoint point1, DoublePoint point2) {
        DoublePoint result = new DoublePoint(point1);
        result.Divide(point2);
        return result;
    }
1036392
public static MattePainter getMattePainter(final int width, final int height,
		final float[] fractions, final Color... colors)
	{
		final LinearGradientPaint gradientPaint = new LinearGradientPaint(0.0f, 0.0f, width, height,
			fractions, colors);
		final MattePainter mattePainter = new MattePainter(gradientPaint);
		return mattePainter;

	}
434182
def +(color2)
    Color.new(
      (self.red + color2.red) / 2.0,
      (self.green + color2.green) / 2.0,
      (self.blue + color2.blue) / 2.0
    )
  end
1200164
public void adjustColor(float r, float g, float b, float a) {
		if (color == Color.white) {
			color = new Color(1,1,1,1f);
		} 
		color.r += r;
		color.g += g;
		color.b += b;
		color.a += a;
	}
678008
def blend_color(color, color2):
    """"""
    r1, g1, b1 = hex_to_rgb(color)
    r2, g2, b2 = hex_to_rgb(color2)

    r3 = int(0.5 * r1 + 0.5 * r2)
    g3 = int(0.5 * g1 + 0.5 * g2)
    b3 = int(0.5 * b1 + 0.5 * b2)

    return rgb_to_hex((r3, g3, b3))
1028451
public static Color colorBetween(final Color c1, final Color c2) {
        final int red = (c1.getRed() + c2.getRed()) / 2;
        final int green = (c1.getGreen() + c2.getGreen()) / 2;
        final int blue = (c1.getBlue() + c2.getBlue()) / 2;
        return new Color(red, green, blue);
    }
817006
public void setGradationColor(GradationMode3D mode, ColorSet colorSet1, ColorSet colorSet2) {
        setGradationColor(mode, new RGBColor(colorSet1), new RGBColor(colorSet2));
    }
245333
public static Palette createPalette(final Color color, final Color... colors) {
        Color[] cs = new Color[colors.length + 1];
        cs[0] = color;
        System.arraycopy(colors, 0, cs, 1, colors.length);
        return new FixedPalette(cs);
    }
258998
public static int modulateColorAlpha(int color, int alpha) {
        int colorAlpha = color >>> 24;
        int scale = alpha + (alpha >> 7);
        int newAlpha = colorAlpha * scale >> 8;
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;
        return newAlpha << 24 | r << 16 | g << 8 | b;
    }