Skip to content

octaviotron/pymap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pymap

Random Map Surface generator with Python

There was a need of having random maps for a game project, so I started to read theory and realize there are really wierd and complex math below it. I was too complicated for me so I decided to use very-very simple math calculations and very-very simple algorithm logics.

This code uses only built-in Python functions, only "random" is imported so so no extra modules needs to be installed.

That is how it works:

  1. One simple matrix(x,y) function creates a random matrix with X long and Y heigh, with values from 0 to 254. Note the numbers in yellow.

first matrix

  1. One simple populate() functions iterates all matrix values and adds a random number in between all cells, keeping values into dots range (blue numbers). Note "12" and "90" values are calculated in row (horizontal) processing. It is simplest than diamond square algorithm.

second matrix

  1. The previous procedure repeats.

third matrix

  1. This is it. This method uses only built-in python basic functions, just needed to import "random" module but who knows... maybe in the future I make a simple-too-random-number-generation function ;-)

The size of the starting random matrix gives the "variation" of the map: bigger starting matrix generates more different zones, if the starting matrix is small, there will be less different terrain zones.

The amount of repetitions gives "smoothness" to the result.

TODO: update the code to Python3

Releases

No releases published

Packages

No packages published

Languages