Coder Social home page Coder Social logo

pymap's Introduction

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

pymap's People

Contributors

octaviotron avatar

Stargazers

 avatar

Watchers

 avatar

pymap's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.