'Simple 2D Perlin Noise in Python
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?
Solution 1:[1]
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.
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | KdotJPG |
Solution 2 | Toby Watkinson |