Documentation ¶
Overview ¶
Package noisey is a library that implements coherent noise algorithms.
The selection is currently:
- 2D/3D Perlin noise (64bit)
- 2D/3D OpenSimplex noise (64bit)
The sources above can be combined with different generators and modifiers like the following:
- 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
Once the noise generators have been set up, a Builder2D object can be created to map a region of noise into a float64 array.
An interface called 'RandomSource' is also exported so that a client can implement a different random number generator and pass it to the noise generators.
Sample programs can be found in the 'examples' directory.
Index ¶
- type Builder2D
- type Builder2DBounds
- type FBMGenerator2D
- type FBMGenerator3D
- type GeneratorJSON
- type NoiseJSON
- type NoiseyGet2D
- type NoiseyGet3D
- type OpenSimplexGenerator
- type PerlinGenerator
- type RandomSeedBuilder
- type RandomSource
- type Scale2D
- type Select2D
- type Select3D
- type SourceJSON
- type Vec2f
- type Vec2i
- type Vec3f
- type Vec3i
- type Vec4f
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder2D ¶
type Builder2D struct { Source NoiseyGet2D Width int Height int Bounds Builder2DBounds Values []float64 }
Builder2D contains the parameters and data for the noise 'map' generated with Build().
func NewBuilder2D ¶
func NewBuilder2D(s NoiseyGet2D, width int, height int) (b Builder2D)
NewBuilder2D creates a new 2D noise 'map' builder of the given size
type Builder2DBounds ¶
type Builder2DBounds struct {
MinX, MinY, MaxX, MaxY float64
}
Builder2DBounds is a simple rectangle type.
type FBMGenerator2D ¶
type FBMGenerator2D struct { NoiseMaker NoiseyGet2D // the interface FBMGenerator2D uses gets noise values Octaves int // the number of octaves to calculate on each Get() Persistence float64 // a multiplier that determines how quickly the amplitudes diminish for each successive octave Lacunarity float64 // a multiplier that determines how quickly the frequency increases for each successive octave Frequency float64 // the number of cycles per unit length }
FBMGenerator2D takes noise and makes fractal Brownian motion values.
func NewFBMGenerator2D ¶
func NewFBMGenerator2D(noise NoiseyGet2D, octaves int, persistence float64, lacunarity float64, frequency float64) (fbm FBMGenerator2D)
NewFBMGenerator2D creates a new fractal Brownian motion generator state. A 'default' fBm would have 1 octave, 0.5 persistence, 2.0 lacunarity and 1.0 frequency.
type FBMGenerator3D ¶
type FBMGenerator3D struct { NoiseMaker NoiseyGet3D // the interface FBMGenerator3D uses gets noise values Octaves int // the number of octaves to calculate on each Get() Persistence float64 // a multiplier that determines how quickly the amplitudes diminish for each successive octave Lacunarity float64 // a multiplier that determines how quickly the frequency increases for each successive octave Frequency float64 // the number of cycles per unit length }
FBMGenerator3D takes noise and makes fractal Brownian motion values.
func NewFBMGenerator3D ¶
func NewFBMGenerator3D(noise NoiseyGet3D, octaves int, persistence float64, lacunarity float64, frequency float64) (fbm FBMGenerator3D)
NewFBMGenerator3D creates a new fractal Brownian motion generator state. A 'default' fBm would have 1 octave, 0.5 persistence, 2.0 lacunarity and 1.0 frequency.
type GeneratorJSON ¶
type GeneratorJSON struct { // Name is the name of the generator that might be referenced by // other GeneratorJSON objects Name string // GeneratorType is a type string to identify what generator to create // on BuildGenerators() GeneratorType string // Sources is an array of strings that are names in the NoiseJSON.Sources // map that are to be used in this generator. Sources []string // Generators is an array of strings that are names in the NoiseJSON.Generators // map that are to be used in this generator. Generators []string Octaves int // Octaves is generator specific ... Persistence float64 // Persistence is generator specific ... Lacunarity float64 // Lacunarity is generator specific ... Frequency float64 // Frequency is generator specific ... LowerBound float64 // LowerBound is generator specific ... UpperBound float64 // LowerBound is generator specific ... EdgeFalloff float64 // EdgeFalloff is generator specific ... Scale float64 // Scale is generator specific ... Bias float64 // Scale is generator specific ... Min float64 // Min is generator specific ... Max float64 // Min is generator specific ... }
GeneratorJSON is a generic data structure for noise generators in noisey. Something like a C union, not all of the fields may be applicable to every generator type.
type NoiseJSON ¶
type NoiseJSON struct { // Seeds uses a name string as a key that can be referenced in SourceJSON // structures and can have predefined seed values. When calling BuildSources(), // a client may pass a function to build the actual RandomSource interface // and is therefore not bound to use this ... Seeds map[string]int64 // Sources uses a name string as a key that can be referenced in other structures // and maps to a SoruceJSON structure that describes how the noise source // should be built. Sources map[string]SourceJSON // Generators is an ordered array of GeneratorJSON objects that define how // noise should be built. Generators []GeneratorJSON // contains filtered or unexported fields }
NoiseJSON is a structure that facilities the saving and loading of JSON representations of a system of seeds, sources and generators of noise.
func LoadNoiseJSON ¶
LoadNoiseJSON unmarshals the JSON from the byte array and returns a NoiseJSON object on success; error otherwise.
func NewNoiseJSON ¶
func NewNoiseJSON() *NoiseJSON
NewNoiseJSON creates a new structure that can be used to save noise settings out to JSON or to load noise settings in from a JSON byte array.
func (*NoiseJSON) BuildGenerators ¶
BuildGenerators creates NoiseyGet2D interface objects based off of the settings in the GeneratorJSON objects in NoiseJSON.Gnerators. This method should be called after BuildSources().
func (*NoiseJSON) BuildSources ¶
func (cfg *NoiseJSON) BuildSources(seedBuilder RandomSeedBuilder) error
BuildSources takes a RandomSeedbuilder function as a parameter to create the actual random number generators from the seed provided and then creates the NoiseyGet2D interface objects based off of settings from SourceJSON structures in NoiseJSON.Sources. This method should be called before BuildGenerators().
func (*NoiseJSON) GetGenerator ¶
func (cfg *NoiseJSON) GetGenerator(name string) NoiseyGet2D
GetGenerator returns a cached generator NoiseyGet2D object. This function Must be called after both BuildSources() and BuildGenerators().
func (*NoiseJSON) SaveNoiseJSON ¶
SaveNoiseJSON marshals the structure into a JSON byte array that is indented nicely.
type NoiseyGet2D ¶
NoiseyGet2D is an interface defining how the modules types get noise from a source.
type NoiseyGet3D ¶
NoiseyGet3D is an interface defining how the modules types get noise from a source.
type OpenSimplexGenerator ¶
type OpenSimplexGenerator struct { Rng RandomSource // random number generator interface Permutations []int // the random permutation table PermGradIndex3D []int }
OpenSimplexGenerator stores the state information for generating opensimplex noise.
func NewOpenSimplexGenerator ¶
func NewOpenSimplexGenerator(rng RandomSource) (osg OpenSimplexGenerator)
NewOpenSimplexGenerator creates a new state object for the open simplex noise generator
type PerlinGenerator ¶
type PerlinGenerator struct { Rng RandomSource // random number generator interface Permutations []int // the random permutation table RandomGradients []Vec4f // the random gradient table }
PerlinGenerator stores the state information for generating perlin noise.
func NewPerlinGenerator ¶
func NewPerlinGenerator(rng RandomSource) (pg PerlinGenerator)
NewPerlinGenerator creates a new state object for the #D perlin noise generator
func (*PerlinGenerator) Get2D ¶
func (pg *PerlinGenerator) Get2D(x, y float64) float64
Get2D calculates the perlin noise at a given 2D coordinate
func (*PerlinGenerator) Get3D ¶
func (pg *PerlinGenerator) Get3D(x, y, z float64) float64
Get3D calculates the perlin noise at a given 3D coordinate
type RandomSeedBuilder ¶
type RandomSeedBuilder func(s int64) RandomSource
RandomSeedBuilder is a type used to construct RandomSource interfaces from a seed listed in the configuration JSON
type RandomSource ¶
RandomSource is a generic interface for a random number generator allowing the user to use the built-in RNG or a custom one that implements this interface.
type Scale2D ¶
type Scale2D struct { // the noise that the select module uses Source NoiseyGet2D // what to scale the noise value from Source by Scale float64 // the const value to add to the scaled noise value Bias float64 // the minimum value to return Min float64 // the maximum value to return Max float64 }
Scale2D is a module that uses gets the noise from Source, scales it and then adds a bias.
func NewScale2D ¶
func NewScale2D(src NoiseyGet2D, scale float64, bias float64, min float64, max float64) (scales Scale2D)
Scale2D creates a new scale 2d module.
type Select2D ¶
type Select2D struct { // the first channel of noise that the select module uses SourceA NoiseyGet2D // the second channel of noise that the select module uses SourceB NoiseyGet2D // a channel of noise that determines whether SourceA or SourceB gets // used as an output for a given coordinate Control NoiseyGet2D // if the value of Control is above LowerBound but below Upper Bound // then SourceB is output, otherwise SourceA is output LowerBound float64 // if the value of Control is above LowerBound but below Upper Bound // then SourceB is output, otherwise SourceA is output UpperBound float64 // the folloff value at the edge of a transition -- if <=0.0 there is an // abrupt transition from SourceA to SourceB, otherwise it specifies // the width of the transition range where values are blended between // the two sources EdgeFalloff float64 }
Select2D is a module that uses SourcesA or SourceB depending on the value coming from Control. If the value from control is between LowerBound and UpperBound then it uses SourceB, but otherwise it will use SourceA.
func NewSelect2D ¶
func NewSelect2D(a, b, c NoiseyGet2D, lower float64, upper float64, edge float64) (selector Select2D)
NewSelect2D creates a new selector 2d module.
type Select3D ¶
type Select3D struct { // the first channel of noise that the select module uses SourceA NoiseyGet3D // the second channel of noise that the select module uses SourceB NoiseyGet3D // a channel of noise that determines whether SourceA or SourceB gets // used as an output for a given coordinate Control NoiseyGet3D // if the value of Control is above LowerBound but below Upper Bound // then SourceB is output, otherwise SourceA is output LowerBound float64 // if the value of Control is above LowerBound but below Upper Bound // then SourceB is output, otherwise SourceA is output UpperBound float64 // the folloff value at the edge of a transition -- if <=0.0 there is an // abrupt transition from SourceA to SourceB, otherwise it specifies // the width of the transition range where values are blended between // the two sources EdgeFalloff float64 }
Select3D is a module that uses SourcesA or SourceB depending on the value coming from Control. If the value from control is between LowerBound and UpperBound then it uses SourceB, but otherwise it will use SourceA.
func NewSelect3D ¶
func NewSelect3D(a, b, c NoiseyGet3D, lower float64, upper float64, edge float64) (selector Select3D)
NewSelect3D creates a new selector 3d module.
type SourceJSON ¶
type SourceJSON struct { // SourceType is a type string used to identify what source module to create // on BuildSources(). SourceType string // Seed is a string that needs to be a name in the NoiseJSON.Seeds map that // is to be used in this generator. Seed string }
SourceJSON describes the source of the random information, like perlin2d.