Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. A 2 dimensional grid (110x110) is used to create the building's heightmap
  2. Many random squares are "drawn" into the grid, each grid's cell covered by these random squares increases the value stored inside of it by one
  3.  
  4. After I made the heightmap, the base of the buildings is drawn this way:
  5.  
  6. let samplesCount = 10000;
  7. for( i = 0; i < samplesCount; i++) {
  8.  
  9. let sampledCell = pick a random cell of the 2 dimensional grid where the heightmap is stored
  10. let wx = count of the consecutive cells that are on the right side of "sampledCell" that have the same height value of "sampledCell"
  11. let wz = count of the consecutive cells that are on the front side of "sampledCell" that have the same height value of "sampledCell"
  12.  
  13. make a building starting from sampledCell coordinates, whose width is wx and depth is wz
  14.  
  15. all the cells "covered" by this building are marked as "used" in another 2 dimensional array, to make sure that the next samples wont draw buildings on top of an existing one (in practice, at the beginning of this for loop I'd check if sampledCell ended up in a "used" cell, in that case I'd just skip the loop body and go to the next iteration
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement