Documentation
¶
Overview ¶
Package opensimplex is a Go implementation of Kurt Spencer's patent-free alternative to Perlin and Simplex noise.
Given a seed, it generates smoothly-changing deterministic random values in 2, 3 or 4 dimensions. It's commonly used for procedurally generated images, geometry, or other randomly-influenced applications that require a random gradient.
For more information on OpenSimplex noise, read more from the creator of the algorithm: http://uniblock.tumblr.com/post/97868843242/noise
Example ¶
noise := New(rand.Int63()) w, h := 100, 100 heightmap := make([]float64, w*h) for y := 0; y < h; y++ { for x := 0; x < w; x++ { xFloat := float64(x) / float64(w) yFloat := float64(y) / float64(h) heightmap[(y*w)+x] = noise.Eval2(xFloat, yFloat) } }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Noise ¶
type Noise interface { Eval2(x, y float64) float64 Eval3(x, y, z float64) float64 Eval4(x, y, z, w float64) float64 }
Noise presents an interface for accessing a seeded noise generator in 2, 3, or 4 dimensions
func New ¶
New constructs a Noise instance with a 64-bit seed. Two Noise instances with the same seed will have the same output.
func NewFbmNoise ¶
NewFbmNoise creates a new FBM Noise function using an input Noise interface.
- octaves are the number of times to apply the noise function - frequency is the frequency with which to sample the source noise - higher frequency means faster rate of change - lacunarity is a multiplier for frequency applied at each octave - persistence is a multiplier for amplitude applied at each octave
**NOTE**: It is not recommended to use normalized noise, since application of octaves has the potential to squeeze the output beyond the [0-1) range. If you need normalized FBM noise, your options are limited:
- Save your noise data and normalize after generation - Run observations on a large data set of points to determine the min and max values, then normalize as you sample
func NewNormalized ¶
NewNormalized constructs a normalized Noise instance with a 64-bit seed. Eval methods will return values in [0, 1). Two Noise instances with the same seed will have the same output.
type Noise32 ¶
type Noise32 interface { Eval2(x, y float32) float32 Eval3(x, y, z float32) float32 Eval4(x, y, z, w float32) float32 }
Noise32 presents an interface for accessing a seeded 32-bit noise generator in 2, 3, or 4 dimensions
func New32 ¶
New32 constructs a Noise32 instance with a 64-bit seed. Two Noise32 instances with the same seed will have the same output.
func NewNormalized32 ¶
NewNormalized32 constructs a normalized Noise32 instance with a 64-bit seed. Eval methods will return values in [0, 1). Two Noise32 instances with the same seed will have the same output.