//A collection of buildings of random heights. Average height adjustable. SIZE = 1.0; FLOORS = 35;//an average number of floors SEED = 20130401;//seed for the random number generator //textures win = new UniformTexture(); win.diffuseColor.setRGB(0.5,0.5,0.5); wall = new UniformTexture(); wall.diffuseColor.setRGB(0.8,0.7,0.4); r = new Random(SEED); void block(double x, double z, int floor) { int k; Cube box = new Cube(10*SIZE,floor*SIZE,10*SIZE); box.setTexture(win, win.getDefaultMapping(box)); Vec3 pos = new Vec3(x,floor*SIZE/2,z); script.addObject(box, new CoordinateSystem(pos, 0,0,0)); box = new Cube(0.5*SIZE,floor*SIZE,0.5*SIZE); box.setTexture(wall, wall.getDefaultMapping(box)); for (k=-5;k<5;k++) { pos = new Vec3(x+k*SIZE,floor*SIZE/2,z+5*SIZE); script.addObject(box, new CoordinateSystem(pos, 0,0,0)); pos = new Vec3(x+(k+1)*SIZE,floor*SIZE/2,z-5*SIZE); script.addObject(box, new CoordinateSystem(pos, 0,0,0)); pos = new Vec3(x-5*SIZE,floor*SIZE/2,z+k*SIZE); script.addObject(box, new CoordinateSystem(pos, 0,0,0)); pos = new Vec3(x+5*SIZE,floor*SIZE/2,z+(k+1)*SIZE); script.addObject(box, new CoordinateSystem(pos, 0,0,0)); } box = new Cube(10.4*SIZE,0.4*SIZE,10.4*SIZE); box.setTexture(wall, wall.getDefaultMapping(box)); for (k=0;k<=floor;k++) { pos = new Vec3(x,k*SIZE,z); script.addObject(box, new CoordinateSystem(pos, 0,0,0)); } } for (int i=-2;i<2;i++) { for (int j=0;j<2;j++) { h = FLOORS/2 + r.nextInt(FLOORS); block(10.0*i,10.0*j,h); } }