Here you can find the source of darker(Color color, float fraction)
Parameter | Description |
---|---|
color | Color to make darker. |
fraction | Darkness fraction. |
public static Color darker(Color color, float fraction)
//package com.java2s; /*/*from w w w .j a v a2 s. c o m*/ * "BSLib", Brainstorm Library. * Copyright (C) 2015 by Sergey V. Zhdanovskih. * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Color; public class Main { /** * Make a color darker. * * @param color Color to make darker. * @param fraction Darkness fraction. * @return Darker color. */ public static Color darker(Color color, float fraction) { float factor = (1.0f - fraction); int rgb = color.getRGB(); int red = (rgb >> 16) & 0xFF; int green = (rgb >> 8) & 0xFF; int blue = (rgb >> 0) & 0xFF; int alpha = (rgb >> 24) & 0xFF; red = (int) (red * factor); green = (int) (green * factor); blue = (int) (blue * factor); red = (red < 0) ? 0 : red; green = (green < 0) ? 0 : green; blue = (blue < 0) ? 0 : blue; return new Color(red, green, blue, alpha); } }