PerlinNoise

Package: Libraries.Compute.Noise · Inherits from: Libraries.Compute.Noise.NoiseGenerator, Libraries.Language.Object

The PerlinNoise class produces Perlin noise, the gradient noise described by Ken Perlin. The plane is covered by a lattice of whole numbered positions, each of which is given a direction. The noise at any point is found by asking the four corners of the cell the point falls in how far it lies along their direction, and blending those four answers together. The result is smooth everywhere and, because the corners always answer the same way, is the same every time a position is asked about. It is worth knowing that the noise is exactly zero at every crossing of the lattice. That is a property of how it is built rather than a fault, but it means noise sampled at whole positions with a frequency of one is flat everywhere. Set a frequency small enough that a lattice cell spans many samples.

Example Code

use Libraries.Compute.Noise.PerlinNoise

class Main
    action Main
        PerlinNoise noise
        noise:SetSeed(1979)
        noise:SetFrequency(0.02)
        noise:SetOctaves(6)

        number value = noise:GetAdditiveNoise(40, 90)
    end
end

Actions

GetNoise(number x, number y)

This action returns the noise at a position, between -1 and 1.

Parameters

  • x number: The position along the first axis.
  • y number: The position along the second axis.

Returns

number

Reseed()

This action shuffles the table of directions the lattice corners answer with. This is the only place the random sequence is touched. Sampling reads the table but never advances it, which is what keeps GetNoise a pure function of position: were the sequence drawn from while sampling, the answer at a place would depend on how many places had been asked about before it, and two terrain tiles sharing an edge would disagree along it.

Inherited Actions

29 actions from Libraries.Compute.Noise.NoiseGenerator
3 actions from Libraries.Language.Object