import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.media.j3d.IndexedTriangleStripArray;
import javax.media.j3d.IndexedGeometryArray;

public class Map extends Shape3D {
    public int nbColumns = 600;
    public int nbRows = 600;

	  public Map()
	  {
        int row;
        int col;
        int index;
        int count = 0;
	  int stripCount = nbColumns * 2;
        int vertexCount = nbRows * nbColumns;
        int indexCount =  (nbRows - 1) * stripCount;
        int stripIndexCounts[] = new int[nbRows - 1];
        float x;
        float y;
        float y_3; //y power 3
        float z;
        Point3f alti[] = new Point3f[vertexCount];
        Color3f coul[] = new Color3f[vertexCount];

		    for (row = 0; row < (nbRows - 1); row ++){
				    stripIndexCounts[row] = stripCount;
			  }
		    IndexedTriangleStripArray triangles = new IndexedTriangleStripArray(
                                              vertexCount,
																							IndexedGeometryArray.COORDINATES |
																							IndexedGeometryArray.NORMALS |
																							IndexedGeometryArray.COLOR_3,
																							indexCount,
                                              stripIndexCounts);
        //Create vertices and colors
        for(row = 0;row < nbRows;row ++) {
            for(col = 0;col < nbColumns;col ++) {
                x = col - nbColumns / 2.0f;
                y = (float)Math.random();
                y_3 = y * y * y;
                z = row - nbRows / 2.0f;
                coul[count] = new Color3f(y_3, y / (1.0f - y), y_3);
                alti[count] = new Point3f(x,y,z);
                count ++;
            }
        }
        triangles.setCoordinates(0,alti);
        triangles.setColors(0,coul);
	  //Set the indices of the indexedGeometry
        for (count = 0, index = 0; count < indexCount; count = count + 2,index ++) {
            triangles.setCoordinateIndex(count,index);
	      triangles.setColorIndex(count,index);
  	      triangles.setCoordinateIndex(count + 1,index + nbColumns);
	      triangles.setColorIndex(count + 1,index + nbColumns);
	  }
        setGeometry(triangles);
   	}
}
