Groovy Documentation

eu.hansolo.gradients
[Java] Class ConicalGradientPaint

java.lang.Object
  eu.hansolo.gradients.ConicalGradientPaint
All Implemented Interfaces:
Paint

public final class ConicalGradientPaint
extends Object

A paint class that creates conical gradients around a given center point It could be used in the same way as LinearGradientPaint and RadialGradientPaint and follows the same syntax. You could use floats from 0.0 to 1.0 for the fractions which is standard but it's also possible to use angles from 0.0 to 360 degrees which is most of the times much easier to handle. Gradients always start at the top with a clockwise direction and you could rotate the gradient around the center by given offset. The offset could also be defined from -0.5 to +0.5 or -180 to +180 degrees. If you would like to use degrees instead of values from 0 to 1 you have to use the full constructor and set the USE_DEGREES variable to true

Authors:
hansolo
Version:
1.0


Nested Class Summary
private class ConicalGradientPaint.ConicalGradientPaintContext

 
Field Summary
private double[] ALPHA_STEP_LOOKUP

private double[] BLUE_STEP_LOOKUP

private Point2D CENTER

private Color[] COLORS

private double[] FRACTION_ANGLES

private double[] GREEN_STEP_LOOKUP

private static float INT_TO_FLOAT_CONST

private double[] RED_STEP_LOOKUP

 
Constructor Summary
ConicalGradientPaint(Point2D CENTER, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS)

Standard constructor which takes the FRACTIONS in values from 0.0f to 1.0f

ConicalGradientPaint(boolean USE_DEGREES, Point2D CENTER, float GIVEN_OFFSET, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS)

Enhanced constructor which takes the FRACTIONS in degress from 0.0f to 360.0f and also an GIVEN_OFFSET in degrees around the rotation CENTER

 
Method Summary
PaintContext createContext(ColorModel COLOR_MODEL, Rectangle DEVICE_BOUNDS, Rectangle2D USER_BOUNDS, AffineTransform TRANSFORM, RenderingHints HINTS)

Color getColorFromFraction(Color START_COLOR, Color DESTINATION_COLOR, int RANGE, int VALUE)

With the START_COLOR at the beginning and the DESTINATION_COLOR at the end of the given RANGE the method will calculate and return the color that equals the given VALUE.

int getTransparency()

private HashMap recalculate(List FRACTION_LIST, List COLOR_LIST, float OFFSET)

Recalculates the fractions in the FRACTION_LIST and their associated colors in the COLOR_LIST with a given OFFSET.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

ALPHA_STEP_LOOKUP

private final double[] ALPHA_STEP_LOOKUP


BLUE_STEP_LOOKUP

private final double[] BLUE_STEP_LOOKUP


CENTER

private final Point2D CENTER


COLORS

private final Color[] COLORS


FRACTION_ANGLES

private final double[] FRACTION_ANGLES


GREEN_STEP_LOOKUP

private final double[] GREEN_STEP_LOOKUP


INT_TO_FLOAT_CONST

private static final float INT_TO_FLOAT_CONST


RED_STEP_LOOKUP

private final double[] RED_STEP_LOOKUP


 
Constructor Detail

ConicalGradientPaint

public ConicalGradientPaint(Point2D CENTER, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS)
Standard constructor which takes the FRACTIONS in values from 0.0f to 1.0f
throws:
IllegalArgumentException
Parameters:
CENTER
GIVEN_FRACTIONS
GIVEN_COLORS


ConicalGradientPaint

public ConicalGradientPaint(boolean USE_DEGREES, Point2D CENTER, float GIVEN_OFFSET, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS)
Enhanced constructor which takes the FRACTIONS in degress from 0.0f to 360.0f and also an GIVEN_OFFSET in degrees around the rotation CENTER
throws:
IllegalArgumentException
Parameters:
USE_DEGREES
CENTER
GIVEN_OFFSET
GIVEN_FRACTIONS
GIVEN_COLORS


 
Method Detail

createContext

@Override
public PaintContext createContext(ColorModel COLOR_MODEL, Rectangle DEVICE_BOUNDS, Rectangle2D USER_BOUNDS, AffineTransform TRANSFORM, RenderingHints HINTS)


getColorFromFraction

public Color getColorFromFraction(Color START_COLOR, Color DESTINATION_COLOR, int RANGE, int VALUE)
With the START_COLOR at the beginning and the DESTINATION_COLOR at the end of the given RANGE the method will calculate and return the color that equals the given VALUE. e.g. a START_COLOR of BLACK (R:0, G:0, B:0, A:255) and a DESTINATION_COLOR of WHITE(R:255, G:255, B:255, A:255) with a given RANGE of 100 and a given VALUE of 50 will return the color that is exactly in the middle of the gradient between black and white which is gray(R:128, G:128, B:128, A:255) So this method is really useful to calculate colors in gradients between two given colors.
Parameters:
START_COLOR
DESTINATION_COLOR
RANGE
VALUE
Returns:
Color calculated from a range of values by given value


getTransparency

@Override
public int getTransparency()


recalculate

private HashMap recalculate(List FRACTION_LIST, List COLOR_LIST, float OFFSET)
Recalculates the fractions in the FRACTION_LIST and their associated colors in the COLOR_LIST with a given OFFSET. Because the conical gradients always starts with 0 at the top and clockwise direction you could rotate the defined conical gradient from -180 to 180 degrees which equals values from -0.5 to +0.5
Parameters:
FRACTION_LIST
COLOR_LIST
OFFSET
Returns:
Hashmap that contains the recalculated fractions and colors after a given rotation


 

Groovy Documentation