Simple 2D Perlin Noise in Python

1.4k Views Asked by At

There is lots of different implementations of 2D perlin noise in Python. My question is there a simple implementation of perlin noise in Python that fits in 1 function or 1 class? Or maybe there is easier-to-implement 2D noise that is similar to perlin noise?

2

There are 2 best solutions below

0
On BEST ANSWER

Does it need to be integers, or is double floating point precision good enough? Can you use Cython? There is a Cython wrapper for FastNoiseLite here: https://github.com/tizilogic/PyFastNoiseLite . You can convert the integers to doubles, with plenty of precision left over.

I would also suggest using the OpenSimplex2 or OpenSimplex2S noise option, rather than Perlin. Perlin as a base noise is very grid-aligned looking. Simplex/OpenSimplex2(S) directly address that.

0
On

The simplest implementation of Perlin noise I have found has been this.

https://pypi.org/project/perlin-noise/

Once installed, and initialised at the top of your code, simply calling the function noise(float) returns the value at that point of the noise field. Additionally, with "unlimited coordinate space", you can simply add more values to the noise function noise(float,float) to change to a 2D, 3D, or higher dimensional noise field.

They provide a couple of basic examples on the website which I found very helpful and sufficient to then be able to implement the library.