本文整理汇总了Java中javafx.scene.canvas.GraphicsContext.fillPolygon方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsContext.fillPolygon方法的具体用法?Java GraphicsContext.fillPolygon怎么用?Java GraphicsContext.fillPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.canvas.GraphicsContext
的用法示例。
在下文中一共展示了GraphicsContext.fillPolygon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
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);
}
}
示例2: drawShapes
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
private static void drawShapes(GraphicsContext gc) {
gc.setFill(Color.GREEN);
gc.setStroke(Color.BLUE);
gc.setLineWidth(5);
gc.strokeLine(40, 10, 10, 40);
gc.fillOval(10, 60, 30, 30);
gc.strokeOval(60, 60, 30, 30);
gc.fillRoundRect(110, 60, 30, 30, 10, 10);
gc.strokeRoundRect(160, 60, 30, 30, 10, 10);
gc.fillArc(10, 110, 30, 30, 45, 240, ArcType.OPEN);
gc.fillArc(60, 110, 30, 30, 45, 240, ArcType.CHORD);
gc.fillArc(110, 110, 30, 30, 45, 240, ArcType.ROUND);
gc.strokeArc(10, 160, 30, 30, 45, 240, ArcType.OPEN);
gc.strokeArc(60, 160, 30, 30, 45, 240, ArcType.CHORD);
gc.strokeArc(110, 160, 30, 30, 45, 240, ArcType.ROUND);
gc.fillPolygon(new double[]{10, 40, 10, 40},
new double[]{210, 210, 240, 240}, 4);
gc.strokePolygon(new double[]{60, 90, 60, 90},
new double[]{210, 210, 240, 240}, 4);
gc.strokePolyline(new double[]{110, 140, 110, 140},
new double[]{210, 210, 240, 240}, 4);
}
示例3: drawRegularNGons
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
private void drawRegularNGons(int n, boolean isFilled) {
GraphicsContext gc = drawingCanvas.getGraphicsContext2D();
gc.setStroke(Color.RED);
gc.setFill(Color.YELLOW);
gc.setLineWidth(5);
double r = 200;
double theta = (360.0 / n) * Math.PI / 180.0;
double w = drawingCanvas.getWidth();
double h = drawingCanvas.getHeight();
double x[] = new double[n];
double y[] = new double[n];
for (int i = 0; i < n; i++) {
double x1 = r * Math.cos(theta * i);
double y1 = r * Math.sin(theta * i);
double x2 = r * Math.cos(theta * (i + 1));
double y2 = r * Math.sin(theta * (i + 1));
x[i] = x1 + w / 2;
y[i] = -y1 + h / 2;
// gc.strokeLine(x1 + w / 2, -y1 + h / 2, x2 + w / 2, -y2 + h / 2);
}
if (isFilled)
gc.fillPolygon(x, y, n);
else gc.strokePolygon(x, y, n);
/*
for (theta = 0; theta <= 360; theta += 360.0 / n) {
double x1 = 0;
double y1 = 0;
double x2 = r * Math.cos(theta * Math.PI / 180.0);
double y2 = r * Math.sin(theta * Math.PI / 180.0);
double w = drawingCanvas.getWidth();
double h = drawingCanvas.getHeight();
gc.strokeLine(x1 + w / 2, -y1 + h / 2, x2 + w / 2, -y2 + h / 2);
}
*/
}