我在做一个游戏,我想自己画山。我使用中点位移来制作山脉,将点存储在一个数组列表中,然后在我的视图中在我的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)。 –