Git Product home page Git Product logo

lake-generator's Introduction

This program procedurally generates images of lakes from the noise package and the included filters. I was originally inspired by this blog post about procedurally generating islands.

But... why?

I have always been interested in the creative powers of computing. When I was younger, I enjoyed playing with different simulators and games with procedural generation. Delegating creative powers to a computer affords a privileged position - you can control the process but escape the minutiae. Even though you define everything you can still explore the results with curiosity and enthusiasm.

In addition, I spent my formative years in Minnesota, Land of 10,000 Lakes, where I escaped up north to the BWCA as often as possible. I think this project is an expression of that same desire to explore.

From a more technical perspective, it offered a good opportunity to explore the numpy library, especially matrix operations, and image processing.

This was probably my first independent project and I have since returned to improve it. The difference is dramatic. I have applied what I've learned in terms of object-oriented design and analyzing algorithms. I wrote an article about this process on my blog. To summarize, the code is much better encapsulated, more user friendly, and about 90% faster.

How does it work?

All the inputs are defined in the config.ini file. Documentation for these settings can be found in Config.py. This makes it easy to change parameters from a text editor.

Perlin noise, to oversimplify it, is a way to generate "smooth" random numbers. Here is a proper explanation.

The process starts with initializing the matrix and filling it with noise values according to the noise parameters defined in config.ini. These will fall between -1.0 and 1.0. That gives us something like so:

noise-img

The image looks weird (unlike "normal" perlin noise) because it's range is between -1.0 and 1.0. We will constrain it to 0.0 and 1.0, but first we will apply our filter (defined in config.ini, or else a random one), which ensures there is some sort of "lake" shape. Here is our matrix less the filter, followed by the filter in use:

filtered-img filtered

Now we will normalize the range so that all of our number fall between 0.0 and 1.0. Darkest is 0.0, lightest is 1.0.

height-img

At this point we can assign certain colors to elements that fall within a certain range. For example, everything below 0.28 will be the deepest level, so it will be set to dark blue. This gives us our final image.

lake-img

In addition, it saves a copy of the config.ini so that you can see what configuration was used and some statistics in JSON.

{
    "low": {
        "value": 880,
        "location": "(522, 1612)"
    },
    "high": {
        "value": 935,
        "location": "(302, 2034)"
    }
}

lake-generator's People

Contributors

blaircurrey avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.