Here you can find the source of blendColor(Color clOne, Color clTwo, double amount)
Parameter | Description |
---|---|
originalColor | a parameter |
brightness | The brightness to use in %. 1 = unchanged. |
public static Color blendColor(Color clOne, Color clTwo, double amount)
//package com.java2s; /*/*from w ww. ja v a2 s. co m*/ * This file is part of smarthomatic, http://www.smarthomatic.org. * Copyright (c) 2013 Uwe Freese * * smarthomatic is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * smarthomatic is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * You should have received a copy of the GNU General Public License along * with smarthomatic. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Color; public class Main { /** * Calculate a brighter or darker version of the originalColor. * @param originalColor * @param brightness The brightness to use in %. 1 = unchanged. */ public static Color blendColor(Color clOne, Color clTwo, double amount) { float fAmount = (float) amount; float fInverse = 1.0f - fAmount; // I had to look up getting color components in java. Google is good :) float afOne[] = new float[3]; clOne.getColorComponents(afOne); float afTwo[] = new float[3]; clTwo.getColorComponents(afTwo); float afResult[] = new float[3]; afResult[0] = afOne[0] * fAmount + afTwo[0] * fInverse; afResult[1] = afOne[1] * fAmount + afTwo[1] * fInverse; afResult[2] = afOne[2] * fAmount + afTwo[2] * fInverse; return new Color(afResult[0], afResult[1], afResult[2]); } }