Documentation ¶
Overview ¶
Package perlin provides coherent noise function over 1, 2 or 3 dimensions This code is go adaptation based on C implementation that can be found here: http://git.gnome.org/browse/gegl/tree/operations/common/perlin/perlin.c (original copyright Ken Perlin)
Index ¶
Examples ¶
Constants ¶
const ( B = 0x100 N = 0x1000 BM = 0xff )
General constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Perlin ¶
type Perlin struct {
// contains filtered or unexported fields
}
Perlin is the noise generator
func NewPerlin ¶
NewPerlin creates new Perlin noise generator In what follows "alpha" is the weight when the sum is formed. Typically it is 2, As this approaches 1 the function is noisier. "beta" is the harmonic scaling/spacing, typically 2, n is the number of iterations and seed is the math.rand seed value to use
func NewPerlinRandSource ¶
NewPerlinRandSource creates new Perlin noise generator In what follows "alpha" is the weight when the sum is formed. Typically it is 2, As this approaches 1 the function is noisier. "beta" is the harmonic scaling/spacing, typically 2, n is the number of iterations and source is source of pseudo-random int64 values
Example ¶
p := perlin.NewPerlinRandSource(alpha, beta, n, rand.NewSource(seed)) for x := 0.; x < 3; x++ { fmt.Printf("%0.0f;%0.4f\n", x, p.Noise1D(x/10)) }
Output: 0;0.0000 1;-0.0086 2;-0.0017
func (*Perlin) Noise1D ¶
Noise1D generates 1-dimensional Perlin Noise value
Example ¶
p := perlin.NewPerlin(alpha, beta, n, seed) for x := 0.; x < 3; x++ { fmt.Printf("%0.0f;%0.4f\n", x, p.Noise1D(x/10)) }
Output: 0;0.0000 1;-0.0086 2;-0.0017
func (*Perlin) Noise2D ¶
Noise2D Generates 2-dimensional Perlin Noise value
Example ¶
p := perlin.NewPerlin(alpha, beta, n, seed) for x := 0.; x < 2; x++ { for y := 0.; y < 2; y++ { fmt.Printf("%0.0f;%0.0f;%0.4f\n", x, y, p.Noise2D(x/10, y/10)) } }
Output: 0;0;0.0000 0;1;-0.2002 1;0;-0.3389 1;1;-0.5045
func (*Perlin) Noise3D ¶
Noise3D Generates 3-dimensional Perlin Noise value
Example ¶
p := perlin.NewPerlin(alpha, beta, n, seed) for x := 0.; x < 2; x++ { for y := 0.; y < 2; y++ { for z := 0.; z < 2; z++ { fmt.Printf("%0.0f;%0.0f;%0.0f;%0.4f\n", x, y, z, p.Noise3D(x/10, y/10, z/10)) } } }
Output: 0;0;0;0.0000 0;0;1;0.2616 0;1;0;-0.0755 0;1;1;0.2020 1;0;0;-0.2138 1;0;1;0.0616 1;1;0;-0.2208 1;1;1;0.0304