Here you can find the source of blend(Color col1, Color col2, float weight1)
Parameter | Description |
---|---|
col1 | the first colour |
col2 | the second colour |
weight1 | the weight given to col1 (from 0.0-1.0) |
public static Color blend(Color col1, Color col2, float weight1)
//package com.java2s; /*/* w w w. java 2s . c o m*/ * Copyright 2010-2012 University of Toronto * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.awt.Color; public class Main { /** * Blend two colours, in the given proportions. Resulting alpha is always * 1.0. * * @param col1 the first colour * @param col2 the second colour * @param weight1 the weight given to col1 (from 0.0-1.0) */ public static Color blend(Color col1, Color col2, float weight1) { float weight2 = (1.0F - weight1) / 255; weight1 /= 255; // This constructor expects values from 0.0F to 1.0F, so weights have to be scaled appropriately. return new Color(col1.getRed() * weight1 + col2.getRed() * weight2, col1.getGreen() * weight1 + col2.getGreen() * weight2, col1.getBlue() * weight1 + col2.getBlue() * weight2); } }