This personal side-project is a Processing application that generates a dynamic terrain mesh using Perlin noise. The terrain is rendered with adjustable parameters, allowing for exploration of different landscape shapes and scales.
The terrain is generated by mapping Perlin noise values to heights on a 2D grid. Perlin noise produces coherent and smooth variations, ideal for natural-looking surfaces like terrains, clouds, or water.
The provided Perlin noise function is a 2D function that yields a number between
The terrain
Let
The Terrain class generates a terrain matrix
Therefore, the normalized altitude value
The normalized altitude value is later multiplied to the chosen maximum altitude value (in pixels) to draw the terrain.
Note
Normalizing the altitude values is a design choice that enforced separation of concerns concept and enhanced code quality, readability, and debugging ease.
The terrain is draw in a 3D scene by treating the beginShape(TRIANGLE_STRIP) function. The resulting triangles are then colored according to their altitude, simulating different biomes.
To simulate the presence of water basins, each altitude value is clamped to a minimum value, defining sea level.
The executable allows to adjust different parameters and see in real time how they effect the resulting terrain. Each parameter has a specific effect on the terrain, as shown in the following table.
| Parameter | Symbol | Description |
|---|---|---|
| Persistence | Specifies how strong is the amplitude difference between octaves. | |
| Lacunarity | Specifies how strong is the frequency difference between octaves. | |
| Number of octaves | Increasing the number of octaves allows to add small details to the terrain. | |
| Terrain size | Width and height of the terrain matrix |
The repository contains:
- Source code (
/source). - Windows executable file (
/exports/windows). - Linux executable file (
/exports/linux).
OpenJDK 17 is needed to run the executables. Alternatively, if you wish to execute (and edit) the source code, all you need to do is:
- Download this repository.
- Download the Processing IDE.
- Open the repository files with the Processing IDE.
- Run the sketch.
Note
Complying with the Processing guidelines, Java access modifiers (e.g., public, private) have been omitted in the source code. Indeed, they do not have effect in .pde files.
This project is licensed under the MIT License. You are free to download, modify, and use the code for personal or commercial projects, provided that proper attribution is given to the original author.
See the LICENSE file for more details.
