int size = RNG.randomNum(0, ((1000/numOfShapes)*10));
int xOrigin = RNG.randomNum(0, 2000);
int yOrigin = RNG.randomNum(0, 1080);
int[] xPoints = null;
int[] yPoints = null;
Polygon p = new Polygon(xPoints, yPoints,3);
//g2.draw(new Line2D.Double(xOrigin, yOrigin, xOrigin+size, yOrigin+size));
//g2.draw(new Line2D.Double(xOrigin+size, yOrigin+size, xOrigin + size, yOrigin));
//g2.draw(new Line2D.Double(xOrigin, yOrigin, xOrigin+size, yOrigin));
g2.fillPolygon(p);
使用3次g2.draw使我成为一个很好的直角三角形,但我想让它充满一种颜色。我应该如何将这些点转换为三角形多边形,以便可以填充?
答案 0 :(得分:1)
int xpoints[] = {xOrigin, xOrigin+size, xOrigin + size};
int ypoints[] = {yOrigin , yOrigin+size, yOrigin};
g2.fillPolygon(xpoints, ypoints, 3);