4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

City generation on a matrix

# What is this stuff?
Do not be fooled by this simple graphics, this is not a complete city, but the basis for procedural generation of the streets. I needed this algorithm for a project I’m developing and to get a good result, I took a long time to think about it.

In green there are free spaces and in white there are streets.
Features that have been sought for this project:

City with roads that complete every free space,
The distance between the streets should be two blocks, minimum 1 and maximum 3 for special cases.

How does it work in general?

The algorithm will return you a matrix of dimensions defined by yourself with 0 for free zones and 1 for roads. You can also add new ids for other future objects such as buildings. In this post is just explained how to create the road network. The first thing to do is to trace the main road goes from side to side of the city:

Once you have created this main road you will need to set the branch points to create the branched roads:

The road goes straightforward for 4 blocks and can not go back. I set the branch points every 4 blocks. For each branch point, I create a road that will have, one or more branched roads.

Example:

The process will be over when the branch points are no longer valid:

Fully generated map.

Without colors

Final print!

How to code this algorithm?

Programming this algorithm can be very complicated if you do not use the right precautions. We will be programming modularly. A general file that will implement its functionality through other sub files.
To see the full post click HERE, it is my blog!

114 upvotes $1.32

Replies (6)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: