mario60
February 16, 2025, 12:08am
1
I am not able to locate the file where the Perlin noise function noise() has been implemented. Please let me have the precise url, thanks.
There it is, at core/src/processing/core/PApplet.java , line 4814
ps.
I see p5.js’ implementation at https://github.com/processing/p5.js/blob/main/src/math/noise.js ;
I see the further implementation at https://discourse.processing.org/t/2d-perlin-noise-function/17602 too.
Glad you found it!
For some context about the noise()
function in Processing/p5.js and where it came from, you might be interested in this recent discussion on the p5.js GitHub:
opened 01:47PM - 17 Dec 24 UTC
Documentation
Discussion
Help Wanted
### noise() is not Perlin noise
Hi,
I've been browsing the documentation o… f the noise function
> [...] Ken Perlin invented `noise()` while animating the original Tron film in the 1980s
and continued to study its implementation. From a first sight, I believe that the implementation found in p5.js deviates from Perlin noise in two characteristics:
### Perlin noise defines gradients at integer grid locations
The noise value associated with a grid locations is given by the dot-product between the stored gradient and the offset vector. If I read your implementation correctly, you are directly assigning a random value to each integer location that is later interpolated.
### Perlin noise is zero at all integer grid locations
if the dot-product becomes zero, either because of orthogonality between the gradient direction and the offset vector or because the offset vector is zero (at integer locations), the resulting noise value becomes zero. Hence, at integer locations the resulting noise should be zero. See https://en.wikipedia.org/wiki/Perlin_noise. In p5.js `noise(x=0,0,0)` will not return a zero noise value in general.
Hence, `noise()` provides smooth noise, but not Perlin noise. I don't believe that's an issue for the intended audience, but in case one relies on the above Perlin characteristics to hold true, you should mentioned the deviations in the docs.
1 Like