I am planning on making a (simple) procedural city generator using Java. I need ideas on whan algorithm to use for the layout, and the actual buildings. The city will mostly have skyscrapers, not really much complex stuff.

For the layout I already have a simple algorithm implemented:

  1. Create a Map with java.awt.Point keys and Integer values. Fill it with all the points in the city's bounds with the value as -1 (unnassigned)
  2. Shuffle the map, and assign the 1st 10 of the keys IDs (from 1-10)
  3. Loop until all points have IDs:
  4. Loop though all points:
  5. Assign points next to an assigned point IDs of the point next to them, if 2 or more points border the point, then randomly choose which ID the point will get.
  6. Stop looping #3-5 when all points have ids
  7. You will end up with 10 random regions. Make roads bordering these regions.
  8. Fill the inside of each region with a randomly spaced and randomly rotated grid

PROBLEM: This is not the fastest way to do it.

What algorithm should I use for the layout. And what should I use to make each building's design? I don't even know how I'm going to do that yet (fractals maybe). I just need some ideas, not actual code.

  • \$\begingroup\$ I'm not sure the algorithm will work as you list it out. In step 3, you assign all points IDs. In step 5, you assign points next to an assigned point (which is all of the points) the ID of the point next to them. So you're going through and changing all of the IDs points you have assigned. Because of this, you'll have a jumble of tiny little islands of each ID, not 10 individual regions. \$\endgroup\$ – fnord Nov 15 '12 at 23:21
  • \$\begingroup\$ relevant: Pixel City. youtube.com/watch?v=-d2-PtK4F6Y \$\endgroup\$ – Trevor Powell Nov 15 '12 at 23:24
  • \$\begingroup\$ it doesn't explain you how it is done, but might give you some ideas : youtube.com/watch?v=FR9xI0GgrBY (city) and youtube.com/watch?v=tUwHRc2zpbo (office generation) \$\endgroup\$ – tigrou Nov 16 '12 at 0:04
  • \$\begingroup\$ Saskia Groenewegen's thesis might give you some ideas: graphics.tudelft.nl/Game_Technology/Groenewegen \$\endgroup\$ – amitp Nov 16 '12 at 0:44
  • 1
    \$\begingroup\$ @Trevor - Shamus has had a blog about this for a while. A very good read in my opinion. shamusyoung.com/twentysidedtale/?p=2940 \$\endgroup\$ – Feltope Nov 16 '12 at 4:43

The procedure you've described seems to be about generating a number of regions on your map. For this problem, I'd suggest using a voronoi diagram instead. A nice tutorial for generating one can be found here. I think this would be faster than your algorithm.

Looking further ahead to road and building generation, there are a lot of different algorithms because of the different requirements. Is this a modern American city with sky-scrapers and suburbs or a historic Roman city with temples and 1-story buildings? This type of difference will affect what you want from your city generator.

If you're interested in reading some academic stuff, I'd recommend a couple of papers on Pascal Müller's site.

| improve this answer | |
  • \$\begingroup\$ it's a modern american city. Sorry for the confusion \$\endgroup\$ – DankMemes Nov 16 '12 at 20:38
  • 1
    \$\begingroup\$ Thanks for the answer though. I'll look into the voronoi diagrams. \$\endgroup\$ – DankMemes Nov 16 '12 at 20:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.