Why doesn't noise() function recalculate inside loops the same way random() does?

If I you put x = random(y); into the draw() function, the function is recalculated for each frame while draw() runs. However x = noise(y); only seems to be calculated once each time the program is run. I checked this by printing the value of x in the console for each iteration of draw(). I don't understand how to use this function.

Answers

  • You need to increment the value of y when using it with noise. Think like this: x=noise(t) where t is time. If t increases slowly, the change is gradual. If t increases fast, the change is as if it were random. If t doesn't change, you get the same value. More info, check shiffman's video series in hisy outube channel: PErlin noise.

    Kf

  • edited April 2017 Answer ✓

    @TonyRamirez -- To better understand this, read the reference:

    In particular:

    In contrast to the random() function, Perlin noise is defined in an infinite n-dimensional space, in which each pair of coordinates corresponds to a fixed semi-random value (fixed only for the lifespan of the program).

    You can think of random() as a fixed 1D array of discontinuous random numbers. Each call to random() returns [0], [1], [2], [3] in the series. The series is seeded differently each time a sketch starts -- or you can specify it with randomSeed().

    You can think of noise() as a fixed 2D or 3D array of locally continuous random numbers. Calls to noise(x,y) return elements of that array -- so if you wish you can move through it with a simple counter, or pass in millis() or frameCount, etc.

    noise(0, i++);
    noise(0, millis());
    noise(0, frameCount);
    

    The noise array is seeded differently each time a sketch starts (just as random() is seeded) -- or you can specify the seed with noiseSeed(). For example, if you needed a whole new noise field each frame (not usually recommended) you could call noiseSeed(frameCount) each frame, and you would get a new array.

    For more information see also: https://en.wikipedia.org/wiki/Perlin_noise

  • Thank you, all!

Sign In or Register to comment.