Class ConicalGradientPaint

java.lang.Object
org.pushingpixels.radiance.theming.internal.utils.ConicalGradientPaint
All Implemented Interfaces:
Paint, Transparency

public final class ConicalGradientPaint extends Object implements Paint
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/
  • Field Details

    • CENTER

      private final Point2D 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

      private final Color[] COLORS
    • INT_TO_FLOAT_CONST

      private static final float INT_TO_FLOAT_CONST
      See Also:
  • Constructor Details

  • 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

      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:
    • createContext

      public PaintContext createContext(ColorModel COLOR_MODEL, Rectangle DEVICE_BOUNDS, Rectangle2D USER_BOUNDS, AffineTransform TRANSFORM, RenderingHints HINTS)
      Specified by:
      createContext in interface Paint
    • getTransparency

      public int getTransparency()
      Specified by:
      getTransparency in interface Transparency