This library natively implements coherent noise algorithms in Go. No 3rd party libraries are required.
Currently it supports the following:
Generators and Modifiers
- FBMGenerator2D - fractal Brownian Motion
- Select2D - choose from source A or B depending on control source
- Scale2D - modify output by multiplying by a scale and adding a bias constant
Additionally, noisey can load settings from a JSON configuration file and create sources and generators from that.
You can get the latest copy of the library using this command:
go get github.com/tbogdala/noisey
You can then use it in your code by importing it:
Noisey comes with a couple examples to show how noise is built:
- noise_text_image: outputs noise through a text gradient to terminal
- noise_gl : makes a simple texture and draws it with OpenGL
- noise_builder_gl: uses the noise builder to compose noise and displays the texture in OpenGL
- noise_from_json_gl: creates the noise builder from JSON and then displays the texture in OpenGL
Below is a screen shot of what noise_from_json_gl outputs.
Full examples can be found in the
examples folder, but this fragment will illustrate basic usage of Perlin noise:
import "github.com/tbogdala/noisey" // ... yadda yadda yadda ... // create a new RNG from Go's built in library with a seed of '1' r := rand.New(rand.NewSource(int64(1))) // create a new perlin noise generator using the RNG created above perlin := noisey.NewPerlinGenerator(r) // get the noise value at point (0.4, 0.2) v := perlin.Get2D(0.4, 0.2)
If you want "smooth" noise, or fractal Brownian motion, then you use the noise generator with another structure:
import "github.com/tbogdala/noisey" // ... yadda yadda yadda ... // create a new RNG from Go's built in library with a seed of '1' r := rand.New(rand.NewSource(int64(1))) // create a new Perlin noise generator using the RNG created above noiseGen := noisey.NewPerlinGenerator(r) // create the fractal Brownian motion modifier based on Perlin fbmPerlin := noisey.NewFBMGenerator2D(&noiseGen) fbmPerlin.Octaves = 5 fbmPerlin.Persistence = 0.25 fbmPerlin.Lacunarity = 2.0 fbmPerlin.Frequency = 1.13 // get the noise value at point (0.4, 0.2) v := fbmPerlin.Get2D(0.4, 0.2)
Samples that display noise to console or OpenGL windows are included. If the
OpenGL examples are desired, you must also install the Go libraries
Other noise generators like Open Simplex can be used in similar manner. Just create the noise generator with the constructor by passing a random number generator:
// create a new RNG from Go's built in library with a seed of '1' r := rand.New(rand.NewSource(int64(1))) // create a new OpenSimplex noise generator using the RNG created above opensimplex := noisey.NewOpenSimplexGenerator(r)
Benchmarks can be run with Go's built-in test tool by executing the following:
cd $GOPATH/src/github.com/tbogdala/noisey go test -cpu 4 -bench .
The cpu flag can be adjusted accordingly, but shouldn't make a difference since the generators don't improve in parallel operation.
Noisey is released under the BSD license. See the
LICENSE file for more details.