mercredi 21 juin 2017

Generating matrix of semi random numbers representing elevation for a topo map

Imagine a topographical map of a continent surrounded by sea with several mountains randomly distributed within the continent. The major part of the land is covered by plains.

IN :

  • The size of a matrix, say, 75x75.
  • The number of mountains, say, 5.

OUT :

A matrix of integer numbers all representing altitude (i.e., Z axis) so that:

  • There are several levels of elevation, from 0 (sea) to 9(mountain peak).
  • No steep slopes: all the adjacent numbers are equal to the number they adjoin or less than it by 1 (assuming decreasing probability of generation of 9s while moving away from the original mountain peak along the X or Y axes). But: it works only withing a range of a mountain.
  • Mountains are not extended: if there are three 9s in a row or column, the next value towards the direction will be 8.
  • The matrix is to be populated by values 0, 1, 2, and 3. The perimeter of the matrix is all zeros.

Question : Using Python libraries, how to implement such a matrix?

Basic example :

0 0 0 0 0 0 0

0 0 1 1 1 0 0

0 1 1 2 1 1 0

0 0 1 1 1 0 0

0 0 0 0 0 0 0




Aucun commentaire:

Enregistrer un commentaire