2014-09-01 2 views
0

다음 그림을 그릴 수 있습니다. 아래에서 이전에 아래에? 이제 끝났습니다 ... 그것은 퍼널이 될 것이므로 모든 타원형이 다각형과 아크 밑에 있었으면합니다. I는 코드 가지고 PSJava Graphics2D : 이전 그림에서 아래 그림을 그립니다.

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); 
    } 

감사 : 다음 좌표 이전 계산된다 이처럼 을 INT (I = pdLen-1; 나는> 0; I -) { 작동되지

UPD :

모든 루프 단계는 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; 

답변

2

루프를 되돌릴 수 있습니다. 좌표의 계산에 대해 생각해야 할 수도 있지만 수행 할 수 있습니다.

일반적으로 이러한 경우에는 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)); 
} 
+0

감사 :

그러나, 싼 (즉, 단순) 솔루션은 페인트하는 무슨 저장 한 다음 역순으로 이러한 모양을 칠하는 것입니다. 작동하며 나중에 알고리즘이 변경됩니다. – Gwalk

관련 문제