S
S
synapse_people2017-02-05 13:32:53
Game development
synapse_people, 2017-02-05 13:32:53

How to generate normal rivers with Perlin noise?

Good afternoon!
Please tell me there is a code like this:

$e = $p->noise2D($x / 10, $y / 10);
if ($e < 0) {
imagesetpixel($image, $x, $y, $blue);
} else {
imagesetpixel($image, $x, $y, $green);
}

(p - Perlin class object (found on github), $e - value from -1 to 1. x,y - it is clear that (in the test from 0 to 700).
The following picture will appear:
c0f9184a8b0a4b529476f3b21e140ca7.png
I would like to know the reason why small islands appear .. And what are the solutions to avoid them. You just need to generate small rivers that are not connected to each other (in the photo - they are connected).. So that there are no areas that are surrounded on all sides by water. How to implement?
Also interested in the reason - why the rivers were generated only in half of the picture??!
For a better understanding, I post the tiles that will be used to display the map:
10778918e9044eca8b53b949ee0819bf.png
Thanks for the answers!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2017-02-05
@BasmanovDaniil

A popular way is to build a height map, select one of the points in the mountains as a source, and then use the pathfinder to go down the height map while drawing the path of the river.
www-cs-students.stanford.edu/~amitp/game-programmi...

N
Nwton, 2017-02-05
@Nwton

Necessarily with noise > No, not necessarily

1) We put a point in a random place in the field. This will be the source of the river;
2) Now let's stretch the river a little. To do this, we use 2 parameters: length and direction. We determine them randomly and draw a straight line / curve for the corresponding blocks / points.
3) Next, we can create a fork in the river, a dead end, or we can repeat the second step. We determine randomly.
4) When, due to the many branches, we have several tributaries, then before repeating the 3rd step, we randomly determine by the end of which of them we will apply it.
5) In the course of implementation, you will understand how to make sure that the tributaries do not intersect and do not create islands. And if you want, you can control the appearance of islands.
By generating rivers/dungeons/mazes using a similar algorithm, we can control the entire construction process (arranging traps, waterfalls, dead ends, npc's, determining the level of confusion), leaving free rein to chance.
I didn't describe the algorithm in sufficient detail, but I'm sure you get the idea.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question