City generation on a matrix

in #programming7 years ago (edited)

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!

Sort:  

Congratulations @gianvy! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of posts published
Award for the number of upvotes received
Award for the number of comments

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Interessante! In bocca al lupo per il tuo progetto!

Di che progetto si tratta? O stai sotto NDA?

E' un progettino mio, nessun NDA, ma per ora non ne parlo!

Congratulations @gianvy! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.21
TRX 0.26
JST 0.038
BTC 95931.40
ETH 3358.80
USDT 1.00
SBD 3.04