Java Code Examples for javafx.scene.paint.Stop#getOffset()

The following examples show how to use javafx.scene.paint.Stop#getOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
/**
 * Get the color at the give {@code position} in the ladder of color stops
 */
private static Color ladder(final double position, final Stop[] stops) {
    Stop prevStop = null;
    for (int i=0; i<stops.length; i++) {
        Stop stop = stops[i];
        if(position <= stop.getOffset()){
            if (prevStop == null) {
                return stop.getColor();
            } else {
                return interpolateLinear((position-prevStop.getOffset())/(stop.getOffset()-prevStop.getOffset()), prevStop.getColor(), stop.getColor());
            }
        }
        prevStop = stop;
    }
    // position is greater than biggest stop, so will we biggest stop's color
    return prevStop.getColor();
}
 
Example 2
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
/**
 * Get the color at the give {@code position} in the ladder of color stops
 */
private static Color ladder(final double position, final Stop[] stops) {
    Stop prevStop = null;
    for (int i=0; i<stops.length; i++) {
        Stop stop = stops[i];
        if(position <= stop.getOffset()){
            if (prevStop == null) {
                return stop.getColor();
            } else {
                return interpolateLinear((position-prevStop.getOffset())/(stop.getOffset()-prevStop.getOffset()), prevStop.getColor(), stop.getColor());
            }
        }
        prevStop = stop;
    }
    // position is greater than biggest stop, so will we biggest stop's color
    return prevStop.getColor();
}
 
Example 3
Source File: GradientLookup.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS  = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double LB_RED     = LOWER_BOUND.getColor().getRed();
    final double LB_GREEN   = LOWER_BOUND.getColor().getGreen();
    final double LB_BLUE    = LOWER_BOUND.getColor().getBlue();
    final double LB_OPACITY = LOWER_BOUND.getColor().getOpacity();

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LB_RED)     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LB_GREEN)   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LB_BLUE)    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LB_OPACITY) * POS;

    double red     = Helper.clamp(0.0, 1.0, (LB_RED     + DELTA_RED));
    double green   = Helper.clamp(0.0, 1.0, (LB_GREEN   + DELTA_GREEN));
    double blue    = Helper.clamp(0.0, 1.0, (LB_BLUE    + DELTA_BLUE));
    double opacity = Helper.clamp(0.0, 1.0, (LB_OPACITY + DELTA_OPACITY));

    return Color.color(red, green, blue, opacity);
}
 
Example 4
Source File: GradientLookup.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS  = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LOWER_BOUND.getColor().getRed())     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LOWER_BOUND.getColor().getGreen())   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LOWER_BOUND.getColor().getBlue())    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

    double red     = LOWER_BOUND.getColor().getRed()     + DELTA_RED;
    double green   = LOWER_BOUND.getColor().getGreen()   + DELTA_GREEN;
    double blue    = LOWER_BOUND.getColor().getBlue()    + DELTA_BLUE;
    double opacity = LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY;

    red     = red < 0 ? 0     : (red > 1 ? 1     : red);
    green   = green < 0 ? 0   : (green > 1 ? 1   : green);
    blue    = blue < 0 ? 0    : (blue > 1 ? 1    : blue);
    opacity = opacity < 0 ? 0 : (opacity > 1 ? 1 : opacity);

    return Color.color(red, green, blue, opacity);
}
 
Example 5
Source File: ColorGradientAxis.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
/**
 * @param value z-Value, values outside of the visible limit are clamped to the extrema
 * @return the color representing the input value on the z-Axis
 */
public Color getColor(final double value) {
    final double offset = (value - getRange().getLowerBound())
                          / (getRange().getUpperBound() - getRange().getLowerBound());

    double lowerOffset = 0.0;
    double upperOffset = 1.0;
    Color lowerColor = Color.TRANSPARENT;
    Color upperColor = Color.TRANSPARENT;

    for (final Stop stop : getColorGradient().getStops()) {
        final double currentOffset = stop.getOffset();
        if (currentOffset == offset) {
            return stop.getColor();
        } else if (currentOffset < offset) {
            lowerOffset = currentOffset;
            lowerColor = stop.getColor();
        } else {
            upperOffset = currentOffset;
            upperColor = stop.getColor();
            break;
        }
    }

    final double interpolationOffset = (offset - lowerOffset) / (upperOffset - lowerOffset);
    return lowerColor.interpolate(upperColor, interpolationOffset);
}
 
Example 6
Source File: Helper.java    From OEE-Designer with MIT License 5 votes vote down vote up
public static final Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
	final double POS = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

	final double DELTA_RED = (UPPER_BOUND.getColor().getRed() - LOWER_BOUND.getColor().getRed()) * POS;
	final double DELTA_GREEN = (UPPER_BOUND.getColor().getGreen() - LOWER_BOUND.getColor().getGreen()) * POS;
	final double DELTA_BLUE = (UPPER_BOUND.getColor().getBlue() - LOWER_BOUND.getColor().getBlue()) * POS;
	final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

	double red = clamp(0, 1, (LOWER_BOUND.getColor().getRed() + DELTA_RED));
	double green = clamp(0, 1, (LOWER_BOUND.getColor().getGreen() + DELTA_GREEN));
	double blue = clamp(0, 1, (LOWER_BOUND.getColor().getBlue() + DELTA_BLUE));
	double opacity = clamp(0, 1, (LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY));

	return Color.color(red, green, blue, opacity);
}
 
Example 7
Source File: GradientLookup.java    From OEE-Designer with MIT License 5 votes vote down vote up
private Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS  = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LOWER_BOUND.getColor().getRed())     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LOWER_BOUND.getColor().getGreen())   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LOWER_BOUND.getColor().getBlue())    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

    double red     = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getRed()     + DELTA_RED));
    double green   = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getGreen()   + DELTA_GREEN));
    double blue    = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getBlue()    + DELTA_BLUE));
    double opacity = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY));

    return Color.color(red, green, blue, opacity);
}
 
Example 8
Source File: GradientLookup.java    From charts with Apache License 2.0 5 votes vote down vote up
private Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS  = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LOWER_BOUND.getColor().getRed())     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LOWER_BOUND.getColor().getGreen())   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LOWER_BOUND.getColor().getBlue())    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

    double red     = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getRed() + DELTA_RED));
    double green   = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getGreen()   + DELTA_GREEN));
    double blue    = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getBlue()    + DELTA_BLUE));
    double opacity = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY));

    return Color.color(red, green, blue, opacity);
}
 
Example 9
Source File: GradientLookup.java    From charts with Apache License 2.0 5 votes vote down vote up
private Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS  = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LOWER_BOUND.getColor().getRed())     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LOWER_BOUND.getColor().getGreen())   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LOWER_BOUND.getColor().getBlue())    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

    double red     = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getRed()     + DELTA_RED));
    double green   = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getGreen()   + DELTA_GREEN));
    double blue    = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getBlue()    + DELTA_BLUE));
    double opacity = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY));

    return Color.color(red, green, blue, opacity);
}
 
Example 10
Source File: Helper.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public static final Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS  = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LOWER_BOUND.getColor().getRed())     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LOWER_BOUND.getColor().getGreen())   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LOWER_BOUND.getColor().getBlue())    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

    double red     = clamp(0, 1, (LOWER_BOUND.getColor().getRed()     + DELTA_RED));
    double green   = clamp(0, 1, (LOWER_BOUND.getColor().getGreen()   + DELTA_GREEN));
    double blue    = clamp(0, 1, (LOWER_BOUND.getColor().getBlue()    + DELTA_BLUE));
    double opacity = clamp(0, 1, (LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY));

    return Color.color(red, green, blue, opacity);
}
 
Example 11
Source File: GradientLookup.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS  = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LOWER_BOUND.getColor().getRed())     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LOWER_BOUND.getColor().getGreen())   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LOWER_BOUND.getColor().getBlue())    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

    double red     = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getRed()     + DELTA_RED));
    double green   = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getGreen()   + DELTA_GREEN));
    double blue    = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getBlue()    + DELTA_BLUE));
    double opacity = Helper.clamp(0.0, 1.0, (LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY));

    return Color.color(red, green, blue, opacity);
}
 
Example 12
Source File: GradientLookup.java    From regulators with Apache License 2.0 5 votes vote down vote up
private Color interpolateColor(final Stop LOWER_BOUND, final Stop UPPER_BOUND, final double POSITION) {
    final double POS = (POSITION - LOWER_BOUND.getOffset()) / (UPPER_BOUND.getOffset() - LOWER_BOUND.getOffset());

    final double DELTA_RED     = (UPPER_BOUND.getColor().getRed()     - LOWER_BOUND.getColor().getRed())     * POS;
    final double DELTA_GREEN   = (UPPER_BOUND.getColor().getGreen()   - LOWER_BOUND.getColor().getGreen())   * POS;
    final double DELTA_BLUE    = (UPPER_BOUND.getColor().getBlue()    - LOWER_BOUND.getColor().getBlue())    * POS;
    final double DELTA_OPACITY = (UPPER_BOUND.getColor().getOpacity() - LOWER_BOUND.getColor().getOpacity()) * POS;

    double red     = clamp(0.0, 1.0, (LOWER_BOUND.getColor().getRed()     + DELTA_RED));
    double green   = clamp(0.0, 1.0, (LOWER_BOUND.getColor().getGreen()   + DELTA_GREEN));
    double blue    = clamp(0.0, 1.0, (LOWER_BOUND.getColor().getBlue()    + DELTA_BLUE));
    double opacity = clamp(0.0, 1.0, (LOWER_BOUND.getColor().getOpacity() + DELTA_OPACITY));

    return Color.color(red, green, blue, opacity);
}