Here you can find the source of rotateHue(Color color, float fraction)
Parameter | Description |
---|---|
color | Starting color |
fraction | Amount to add to the hue. The integer part is discarded to leave a number in [0,1) |
public static Color rotateHue(Color color, float fraction)
//package com.java2s; /*// ww w .j a v a2 s . c o m * BioJava development code * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. If you do not have a copy, * see: * * http://www.gnu.org/copyleft/lesser.html * * Copyright for this code is held jointly by the individual * authors. These should be listed in @author doc comments. * * For more information on the BioJava project and its aims, * or to join the biojava-l mailing list, visit the home page * at: * * http://www.biojava.org/ * * Created on May 20, 2010 * Author: Andreas Prlic * */ import java.awt.*; public class Main { /** * Rotate a color through HSB space * @param color Starting color * @param fraction Amount to add to the hue. The integer part is discarded to leave a number in [0,1) * @return */ public static Color rotateHue(Color color, float fraction) { float af[] = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); float hue = af[0]; float saturation = af[1]; float brightness = af[2]; float hueNew = hue + fraction; Color hsb = Color.getHSBColor(hueNew, saturation, brightness); return new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), color.getAlpha()); } }