Class ConicalGradientPaint
java.lang.Object
org.pushingpixels.radiance.theming.internal.utils.ConicalGradientPaint
- All Implemented Interfaces:
Paint
,Transparency
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.
Contributed under the BSD license by Gerrit Grunwald. Original code from
https://www.jug-muenster.de/java2d-conical-gradient-paint-674/
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double[]
private final double[]
private final Point2D
private final Color[]
private final double[]
private final double[]
private static final float
private final double[]
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
Constructor Summary
ConstructorsConstructorDescriptionConicalGradientPaint
(boolean USE_DEGREES, Point2D CENTER, float GIVEN_OFFSET, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS) ConicalGradientPaint
(Point2D CENTER, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS) -
Method Summary
Modifier and TypeMethodDescriptioncreateContext
(ColorModel COLOR_MODEL, Rectangle DEVICE_BOUNDS, Rectangle2D USER_BOUNDS, AffineTransform TRANSFORM, RenderingHints HINTS) 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
recalculate
(List<Float> FRACTION_LIST, List<Color> COLOR_LIST, float OFFSET) Recalculates the fractions in the FRACTION_LIST and their associated colors in the COLOR_LIST with a given OFFSET.
-
Field Details
-
CENTER
-
FRACTION_ANGLES
private final double[] FRACTION_ANGLES -
RED_STEP_LOOKUP
private final double[] RED_STEP_LOOKUP -
GREEN_STEP_LOOKUP
private final double[] GREEN_STEP_LOOKUP -
BLUE_STEP_LOOKUP
private final double[] BLUE_STEP_LOOKUP -
ALPHA_STEP_LOOKUP
private final double[] ALPHA_STEP_LOOKUP -
COLORS
-
INT_TO_FLOAT_CONST
private static final float INT_TO_FLOAT_CONST- See Also:
-
-
Constructor Details
-
ConicalGradientPaint
public ConicalGradientPaint(Point2D CENTER, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
ConicalGradientPaint
public ConicalGradientPaint(boolean USE_DEGREES, Point2D CENTER, float GIVEN_OFFSET, float[] GIVEN_FRACTIONS, Color[] GIVEN_COLORS) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
-
Method Details
-
recalculate
private HashMap<Float,Color> recalculate(List<Float> FRACTION_LIST, List<Color> 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:
-
getColorFromFraction
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:
-
createContext
public PaintContext createContext(ColorModel COLOR_MODEL, Rectangle DEVICE_BOUNDS, Rectangle2D USER_BOUNDS, AffineTransform TRANSFORM, RenderingHints HINTS) - Specified by:
createContext
in interfacePaint
-
getTransparency
public int getTransparency()- Specified by:
getTransparency
in interfaceTransparency
-