Java Code Examples for javafx.scene.canvas.GraphicsContext#fillPolygon()

The following examples show how to use javafx.scene.canvas.GraphicsContext#fillPolygon() . 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: FireworksSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void draw(GraphicsContext context) {
    final double x = Math.round(posX);
    final double y = Math.round(posY);
    final double xVel = (x - lastPosX) * -5;
    final double yVel = (y - lastPosY) * -5;
    // set the opacity for all drawing of this particle
    context.setGlobalAlpha(Math.random() * this.alpha);
    // draw particle
    context.setFill(color);
    context.fillOval(x-size, y-size, size+size, size+size);
    // draw the arrow triangle from where we were to where we are now
    if (hasTail) {
        context.setFill(Color.rgb(255,255,255,0.3));
        context.fillPolygon(new double[]{posX + 1.5,posX + xVel,posX - 1.5}, 
                new double[]{posY,posY + yVel,posY}, 3);
    }
}
 
Example 2
Source File: FireworksSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void draw(GraphicsContext context) {
    final double x = Math.round(posX);
    final double y = Math.round(posY);
    final double xVel = (x - lastPosX) * -5;
    final double yVel = (y - lastPosY) * -5;
    // set the opacity for all drawing of this particle
    context.setGlobalAlpha(Math.random() * this.alpha);
    // draw particle
    context.setFill(color);
    context.fillOval(x-size, y-size, size+size, size+size);
    // draw the arrow triangle from where we were to where we are now
    if (hasTail) {
        context.setFill(Color.rgb(255,255,255,0.3));
        context.fillPolygon(new double[]{posX + 1.5,posX + xVel,posX - 1.5}, 
                new double[]{posY,posY + yVel,posY}, 3);
    }
}
 
Example 3
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
  Color f = cpool.getColor(color.x, color.y, color.z, .4f);
  Color s = cpool.getColor(color.x, color.y, color.z, 1f);
  GraphicsContext g = getGraphics();
  saveState(g);
  double[] xs = xDoublePool.get(vertexCount);
  double[] ys = yDoublePool.get(vertexCount);
  for (int i = 0; i < vertexCount; i++) {
    getWorldToScreenToOut(vertices[i], temp);
    xs[i] = temp.x;
    ys[i] = temp.y;
  }
  g.setLineWidth(stroke);
  g.setFill(f);
  g.fillPolygon(xs, ys, vertexCount);
  g.setStroke(s);
  g.strokePolygon(xs, ys, vertexCount);
  restoreState(g);
}
 
Example 4
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
/**
 * @param gc the graphics context from the Canvas parent
 * @param localCachedPoints reference to local cached data point object
 */
protected void drawErrorSurface(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    final long start = ProcessingProfiler.getTimeStamp();

    DefaultRenderColorScheme.setFillScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);

    final int nDataCount = localCachedPoints.actualDataCount;
    final int nPolygoneEdges = 2 * nDataCount;
    final double[] xValuesSurface = DoubleArrayCache.getInstance().getArrayExact(nPolygoneEdges);
    final double[] yValuesSurface = DoubleArrayCache.getInstance().getArrayExact(nPolygoneEdges);

    final int xend = nPolygoneEdges - 1;
    for (int i = 0; i < nDataCount; i++) {
        xValuesSurface[i] = localCachedPoints.xValues[i];
        yValuesSurface[i] = localCachedPoints.errorYNeg[i];
        xValuesSurface[xend - i] = localCachedPoints.xValues[i];
        yValuesSurface[xend - i] = localCachedPoints.errorYPos[i];
    }
    // swap y coordinates at mid-point
    if (nDataCount > 4) {
        final double yTmp = yValuesSurface[nDataCount - 1];
        yValuesSurface[nDataCount - 1] = yValuesSurface[xend - nDataCount + 1];
        yValuesSurface[xend - nDataCount + 1] = yTmp;
    }

    gc.setFillRule(FillRule.EVEN_ODD);
    gc.fillPolygon(xValuesSurface, yValuesSurface, nPolygoneEdges);

    drawPolyLine(gc, localCachedPoints);
    drawBars(gc, localCachedPoints);
    drawMarker(gc, localCachedPoints);
    drawBubbles(gc, localCachedPoints);

    DoubleArrayCache.getInstance().add(xValuesSurface);
    DoubleArrayCache.getInstance().add(yValuesSurface);

    ProcessingProfiler.getTimeDiff(start);
}
 
Example 5
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected static void drawPolyLineArea(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    final int n = localCachedPoints.actualDataCount;
    if (n == 0) {
        return;
    }

    // need to allocate new array :-(
    final double[] newX = DoubleArrayCache.getInstance().getArrayExact(n + 2);
    final double[] newY = DoubleArrayCache.getInstance().getArrayExact(n + 2);

    final double zero = localCachedPoints.yZero;
    System.arraycopy(localCachedPoints.xValues, 0, newX, 0, n);
    System.arraycopy(localCachedPoints.yValues, 0, newY, 0, n);
    newX[n] = localCachedPoints.xValues[n - 1];
    newY[n] = zero;
    newX[n + 1] = localCachedPoints.xValues[0];
    newY[n + 1] = zero;

    gc.save();
    DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle);
    // use stroke as fill colour
    gc.setFill(gc.getStroke());
    gc.fillPolygon(newX, newY, n + 2);
    gc.restore();

    // release arrays to cache
    DoubleArrayCache.getInstance().add(newX);
    DoubleArrayCache.getInstance().add(newY);
}
 
Example 6
Source File: Hexagon.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public void drawHexagon(final GraphicsContext gc) {
    final ObservableList<Double> points = getPoints();
    final int nPoints = points.size() / 2;
    final double[] xPoints = new double[nPoints];
    final double[] yPoints = new double[nPoints];
    for (int i = 0; i < nPoints; i++) {
        xPoints[i] = 0.5 + Math.round(points.get(2 * i));
        yPoints[i] = 0.5 + Math.round(points.get(2 * i + 1));
    }
    gc.fillPolygon(xPoints, yPoints, nPoints);
    gc.strokePolygon(xPoints, yPoints, nPoints);
}
 
Example 7
Source File: Hexagon.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public void drawHexagon(final GraphicsContext gc, Direction... directions) {
    final ObservableList<Double> points = getPoints();
    final int nPoints = points.size() / 2;
    final double[] xPoints = new double[nPoints];
    final double[] yPoints = new double[nPoints];
    for (int i = 0; i < nPoints; i++) {
        xPoints[i] = 0.5 + Math.round(points.get(2 * i));
        yPoints[i] = 0.5 + Math.round(points.get(2 * i + 1));
    }
    gc.fillPolygon(xPoints, yPoints, nPoints);

    for (final Direction side : directions) {
        switch (side) {
        case EAST:
            gc.strokeLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
            break;
        case NORTHEAST:
            gc.strokeLine(xPoints[1], yPoints[1], xPoints[2], yPoints[2]);
            break;
        case NORTHWEST:
            gc.strokeLine(xPoints[2], yPoints[2], xPoints[3], yPoints[3]);
            break;
        case WEST:
            gc.strokeLine(xPoints[3], yPoints[3], xPoints[4], yPoints[4]);
            break;
        case SOUTHWEST:
            gc.strokeLine(xPoints[4], yPoints[4], xPoints[5], yPoints[5]);
            break;
        case SOUTHEAST:
            gc.strokeLine(xPoints[5], yPoints[5], xPoints[0], yPoints[0]);
            break;
        default:
            break;
        }
    }
    // gc.strokePolygon(xPoints, yPoints, nPoints);
}
 
Example 8
Source File: Arrow.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
private static void fillPolygon( GraphicsContext graphics, Direction direction ) {
    switch ( direction ) {
        case UP:
            graphics.fillPolygon( upDownXs, upYs, 3 );
            break;
        case DOWN:
            graphics.fillPolygon( upDownXs, downYs, 3 );
            break;
    }
}
 
Example 9
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * NaN compatible algorithm
 *
 * @param gc the graphics context from the Canvas parent
 * @param localCachedPoints reference to local cached data point object
 */
protected void drawErrorSurfaceNaNCompatible(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    final long start = ProcessingProfiler.getTimeStamp();

    DefaultRenderColorScheme.setFillScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);

    gc.setFillRule(FillRule.EVEN_ODD);

    final int nDataCount = localCachedPoints.actualDataCount;
    final int nPolygoneEdges = 2 * nDataCount;
    final double[] xValuesSurface = DoubleArrayCache.getInstance().getArrayExact(nPolygoneEdges);
    final double[] yValuesSurface = DoubleArrayCache.getInstance().getArrayExact(nPolygoneEdges);

    final int xend = nPolygoneEdges - 1;
    int count = 0;
    for (int i = 0; i < nDataCount; i++) {
        final double x = localCachedPoints.xValues[i];
        final double yen = localCachedPoints.errorYNeg[i];
        final double yep = localCachedPoints.errorYPos[i];

        if (Double.isFinite(yen) && Double.isFinite(yep)) {
            xValuesSurface[count] = x;
            yValuesSurface[count] = yep;
            xValuesSurface[xend - count] = x;
            yValuesSurface[xend - count] = yen;
            count++;
        } else if (count != 0) {
            // remove zeros and plot intermediate segment
            compactVector(xValuesSurface, count);
            compactVector(yValuesSurface, count);

            gc.fillPolygon(xValuesSurface, yValuesSurface, 2 * count);
            count = 0;
        }
    }
    if (count > 0) {
        // swap y coordinates at mid-point
        // remove zeros and plot intermediate segment
        compactVector(xValuesSurface, count);
        compactVector(yValuesSurface, count);
        if (count > 4) {
            final double yTmp = yValuesSurface[count - 1];
            yValuesSurface[count - 1] = yValuesSurface[count];
            yValuesSurface[count] = yTmp;
        }

        gc.fillPolygon(xValuesSurface, yValuesSurface, 2 * count);
    }

    drawPolyLine(gc, localCachedPoints);
    drawBars(gc, localCachedPoints);
    drawMarker(gc, localCachedPoints);
    drawBubbles(gc, localCachedPoints);

    DoubleArrayCache.getInstance().add(xValuesSurface);
    DoubleArrayCache.getInstance().add(yValuesSurface);

    ProcessingProfiler.getTimeDiff(start);
}
 
Example 10
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
protected static void drawPolyLineHistogramFilled(final GraphicsContext gc,
        final CachedDataPoints localCachedPoints) {
    final int n = localCachedPoints.actualDataCount;
    if (n == 0) {
        return;
    }

    // need to allocate new array :-(
    final double[] newX = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));
    final double[] newY = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));

    final double xRange = localCachedPoints.xMax - localCachedPoints.xMin;
    double diffLeft;
    double diffRight = n > 0 ? 0.5 * (localCachedPoints.xValues[1] - localCachedPoints.xValues[0]) : 0.5 * xRange;
    newX[0] = localCachedPoints.xValues[0] - diffRight;
    newY[0] = localCachedPoints.yZero;
    for (int i = 0; i < n; i++) {
        diffLeft = localCachedPoints.xValues[i] - newX[2 * i];
        diffRight = i + 1 < n ? 0.5 * (localCachedPoints.xValues[i + 1] - localCachedPoints.xValues[i]) : diffLeft;
        if (i == 0) {
            diffLeft = diffRight;
        }

        newX[2 * i + 1] = localCachedPoints.xValues[i] - diffLeft;
        newY[2 * i + 1] = localCachedPoints.yValues[i];
        newX[2 * i + 2] = localCachedPoints.xValues[i] + diffRight;
        newY[2 * i + 2] = localCachedPoints.yValues[i];
    }
    // last point
    newX[2 * (n + 1) - 1] = localCachedPoints.xValues[n - 1] + diffRight;
    newY[2 * (n + 1) - 1] = localCachedPoints.yZero;

    gc.save();
    DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle);
    // use stroke as fill colour
    gc.setFill(gc.getStroke());
    gc.fillPolygon(newX, newY, 2 * (n + 1));
    gc.restore();

    // release arrays to cache
    DoubleArrayCache.getInstance().add(newX);
    DoubleArrayCache.getInstance().add(newY);
}