Я создаю игру и хочу нарисовать горы сам.Я создаю горы, используя смещение средней точки, сохраняю точки в массиве, а затем извлекаю их в моем Jpanel, на мой взгляд.Я рисую другие вещи, такие как трава, и g2 заполнит их цветами, но не моя гора.Вот результат:
http://i.imgur.com/5ty3C.png
Вот код:
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);
}
}