gpt4 book ai didi

Java Graphics2D : draw the following figure under the previous

转载 作者:行者123 更新时间:2023-12-02 05:30:24 24 4
gpt4 key购买 nike

如何在上图绘制下图?现在结束了......它将是漏斗,所以我希望每个下一个椭圆形都位于多边形和圆弧下方。我有这样的代码:

    for (int i = 0; i < pdLen; i++) {
....
....
g2.fillPolygon(poly);

g2.fillOval(topLeft[0], topLeft[1] - 10, topRight[0] - topLeft[0], arcHeight);

g2.fillArc(botLeft[0], botLeft[1] - arcHeight / 2, botRight[0] - botLeft[0], arcHeight, 0, -180);
}

谢谢PS:以下坐标是根据之前的坐标计算得出的,因此 for(int i=pdLen-1;i>0;i--){ 不起作用

更新:

每个循环步骤都会计算 topLeft 和 topRight。

        int[] topLeft = {(int)Math.round( startX + ( procSum/onePixX ) ), (int)Math.round( startY + ( procSum/onePixY ) )};
int[] topRight = {(int)Math.round( topRightX - ( procSum/onePixX ) ), (int)Math.round( startY + ( procSum/onePixY ) )};
procSum += (pieceData[i] * pieceProc);

int[] botLeft = {(int)Math.round( startX + ( procSum/onePixX ) ), (int)Math.round( startY + ( procSum/onePixY ) )};
int[] botRight = {(int)Math.round( topRightX - ( procSum/onePixX ) ), (int)Math.round( startY + ( procSum/onePixY ) )};
procSum += padProc;

最佳答案

您可以反转循环。您可能需要考虑坐标的计算,但这是可以完成的。

一般来说,在这种情况下,您应该发布 MCVE 。这将为每个人节省大量时间。

但是,廉价(即简单)的解决方案是存储需要绘制的内容,然后以相反的顺序绘制这些形状:

List<Shape> ovals = new ArrayList<Shape>();
List<Shape> arcs = new ArrayList<Shape>();
for (int i = 0; i < pdLen; i++) {
//g2.fillOval(topLeft[0], topLeft[1] - 10, topRight[0] - topLeft[0], arcHeight);
ovals.add(new Ellipse2D.Double(topLeft[0], topLeft[1] - 10, topRight[0] - topLeft[0], arcHeight));
//g2.fillArc(botLeft[0], botLeft[1] - arcHeight / 2, botRight[0] - botLeft[0], arcHeight, 0, -180);
arcs.add(new Arc2D.Double(botLeft[0], botLeft[1] - arcHeight / 2, botRight[0] - botLeft[0], arcHeight, 0, -180));
}
for (int i=ovals.size()-1; i>=0; i--)
{
g2.fill(ovals.get(i));
g2.fill(arcs.get(i));
}

关于Java Graphics2D : draw the following figure under the previous,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25604667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com