While noise is unwanted in many occasions, it is a great tool for procedural generation and has many uses. In this recipe, we'll explore jMonkeyEngine's FractalSum
class and generate an image based on the output. This can be used as a heightmap for a terrain, but we are not limited by that. With some tweaking, we could get a basis to cover a forest or city.
This recipe relies on a way to output an image. Either use your own method to do this or refer to the The ImageGenerator class section in Appendix, Information Fragments, which provides an example of how to do it.
To generate a heightmap, perform the following steps:
We will start by creating a class called
NoiseMapGenerator
.In its constructor, define a new
FractalSum
instance and store it in a field calledfractalSum
.Next, create a public method called
generateNoiseMap
that takes an integer parameter calledsize
, a float parameter calledfrequency
, and an integer parameter called...