Java Graphics Rotate rotateHue(Color color, float fraction)

Here you can find the source of rotateHue(Color color, float fraction)

Description

Rotate a color through HSB space

License

GNU General Public License

Parameter

Parameter Description
color Starting color
fraction Amount to add to the hue. The integer part is discarded to leave a number in [0,1)

Declaration

public static Color rotateHue(Color color, float fraction) 

Method Source Code


//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());
    }
}

Related

  1. rotateByAngle(final Point2D pos, final Point2D center, final double angle)
  2. rotateClockwise(Path source, Path target)
  3. rotateCoor(float x, float y, float theta)
  4. rotateCoorAroundPoint(float x, float y, float xctr, float yctr, float theta)
  5. rotateHue(Color color, float fraction)
  6. rotateMoveClockwise(Point move, int size)
  7. rotatePoint(double x0, double y0, double x, double y, double a)
  8. rotatePoint(double x0, double y0, double x, double y, double angle)
  9. rotatePoint(int x, int y, int xC, int yC, float angle)