我在做一個遊戲,我想自己畫山。我使用中點位移來製作山脈,將點存儲在一個數組列表中,然後在我的視圖中在我的Jpanel中檢索它們。我畫了其他的東西,像草,G2會填充顏色,但不是我的山。下面是結果:Graphics2D不會填充路徑
下面的代碼:
Point2D.Double start = new Point2D.Double(50, 400);
listePoints.add(start);
Point2D.Double end = new Point2D.Double(modele.getLargeur(), 400);
listePoints.add(end);
this.maxIterations = 9;
int iterations = 0;
int minHeight = 5;
double nbrRandom = 10;
while(iterations < this.maxIterations) {
iterations ++;
int counter = 0;
int size = listePoints.size()-1;
int index = 0;
while (compteur < size) {
Point2D.Double point1 = listePoints.get(index);
Point2D.Double point2 = listePoints.get(index+1);
double milieu = Math.abs(point2.x - point1.x)/2;
int orientation = Equations.randInt(1);
switch(orientation) {
case 0: orientation = -1;break;
case 1: orientation = 1;break;
}
Point2D.Double point3 = new Point2D.Double(point1.x+milieu,point1.y+(Equations.rand((nbrRandom+iterations = 0;
int minHeight)*orientation)));
nbrRandom = nbrRandom /2;
listePoints.add(index+1,point3);
index +=2;
counter++ ;
}
}
Point2D.Double point1 = new Point2D.Double(start.x,500);
listePoints.add(0,point1);
point1 = new Point2D.Double(end.x,500);
listePoints.add(listePoints.size(),point1);
point1 = new Point2D.Double(start.x,500);
listePoints.add(listePoints.size(),point1);
/***************************** VIEW **/
Path2D.Double path = new Path2D.Double(Path2D.Double.WIND_EVEN_ODD);
for (int j = 0;j < list.size()-1; j++) {
Point2D.Double point1 = list.get(j);
Point2D.Double point2 =list.get(j+1);
path.moveTo(point1.x, point1.y);
path.lineTo(point2.x, point2.y);
path.closePath();
g2.draw(path);
g2.fill(path);
}
}
1)爲了更好地提供幫助,請發佈[SSCCE](http://sscce.org/)。 2)你有問題嗎? –
我去編輯帖子以線上截屏,但選擇不在線內。這是一個不太清楚,並且像素表示很大的簡單問題。 3)爲了製作精美的屏幕截圖,請參閱[如何創建屏幕截圖?]的提示(http://meta.stackexchange.com/questions/99734/how-do-i-create-a-screenshot-to-說明-A-POST)。最重要的提示是a)小! b)白色BG。除了這些提示之外,請勿在上傳之前調整圖像大小。調整大小通常會使圖像*以字節爲單位變大,但不夠清晰和精確。 –
*「不要調整圖像大小」*(愚蠢的笑容)忽略那個評論 - 這是我的瀏覽器在調整大小(從巨大的1632x1224)。 –