Documentation
¶
Overview ¶
fastnoise is a noise generation package with a large selection of noise algorithms.
Index ¶
- func DomainWarp2D[T Float, N Coord](x, y N, ns *NoiseState[T]) (T, T)
- func DomainWarp3D[T Float, N Coord](x, y, z N, ns *NoiseState[T]) (T, T, T)
- func Value2D[T Float, N Coord](x, y N, ns *NoiseState[T]) T
- func Value3D[T Float, N Coord](x, y, z N, ns *NoiseState[T]) T
- type CellularDistanceFunc
- type CellularReturnType
- type Coord
- type DomainWarpType
- type Float
- type FractalType
- type NoiseState
- type NoiseType
- type RotationType3D
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DomainWarp2D ¶ added in v1.2.0
func DomainWarp2D[T Float, N Coord](x, y N, ns *NoiseState[T]) (T, T)
DomainWarp2D warps the input position using current domain warp settings.
Example ¶
package main
import (
"fmt"
"github.com/setanarut/fastnoise"
)
func main() {
chars := " .:;+=xX$"
noiseState := fastnoise.NewNoiseState[float32]()
noiseState.Frequency = 0.05
noiseState.DomainWarpType = fastnoise.DomainWarpOpenSimplex2Reduced
noiseState.DomainWarpAmp = 30
for y := range 10 {
for x := range 80 {
wx, wy := fastnoise.DomainWarp2D(x, y, noiseState)
v := fastnoise.Value2D(wx, wy, noiseState)
i := int((v + 1) / 2 * float32(len(chars)))
fmt.Print(string(chars[i]))
}
fmt.Println()
}
}
Output: ++=xXX=+;;;+++==+;. :x$x;.. .:;;++;::....:;;. .;++==xXX$XX=+xX+. ;X$Xx+;;;;;: =xxX$x+;;+++;;;;:..;xXx;;;+++;:....::.. .:. .;+====xxXxx==XX; .=X$Xx++;;;;: XX$$X=+;+++++;;:::;xXx++xX$$XXx+;:... .. .;==========xX$x:.;X$Xx=++;;;;; X$Xx=+++====++;;;+=x=++x$XXxxxxx=+;:. ... .. .+xXXxx===xxX$X+.;x$Xx+;;;;;;;: +=++;++=xx===++;+=x=;+xx=+;;;;+++=+;:............:=X$$$XXXXX$$X=;;x$X=;:..:::::: .::;+=xxxxx==++++==;;==+::;++;;:;+=+;::::::::::..+X$$$$$$$$$$X=++xXx;:. ..::: :;+=xxxxxxxx==+++=+:;++::;===++::;+=++;;;;;;;;:::x$$XXXxxxxxx=+=xX=;::::........ =xXXXXXXx======++=;:;+:.:=xxx=+;::;+=++++++++;::+X$XXxx====++=xXX=++=xxx=+;::... X$$$$$Xx=++++==++=;.:;..;xXXxx=+:.:;++++++++;;:+xXXXXx=======xXXx++xX$$XXx=+;::. $$$$$$Xx=;;;;=====;.::..+xXXxx=+;..::;;;;;;;::;=XxX$XxxxXXXXXXXx==xX$$$XXx===+;;
func DomainWarp3D ¶ added in v1.2.0
func DomainWarp3D[T Float, N Coord](x, y, z N, ns *NoiseState[T]) (T, T, T)
DomainWarp3D warps the input position using current domain warp settings.
Example ¶
package main
import (
"fmt"
"github.com/setanarut/fastnoise"
)
func main() {
chars := " .:;+=xX$"
noiseState := fastnoise.NewNoiseState[float32]()
noiseState.Frequency = 0.05
noiseState.DomainWarpType = fastnoise.DomainWarpOpenSimplex2Reduced
noiseState.DomainWarpAmp = 30
for y := range 10 {
for x := range 80 {
wx, wy, wz := fastnoise.DomainWarp3D(y, x, 300, noiseState)
v := fastnoise.Value3D(wx, wy, wz, noiseState)
i := int((v + 1) / 2 * float32(len(chars)))
fmt.Print(string(chars[i]))
}
fmt.Println()
}
}
Output: ......:;;:. .::;;++=xxx=++;;:::::::::::::::;++;:::+:. .::;;::.:;=xXx+:. ..: :::.. .:;:. ..:;+=xXXx=+:::::::::::::::::::;+;;::;;. .::::..:+=xxx+:. .:: :::.. .:+;:....:;+=xXXXx=;::::::::::::::::::::;+;::;;: ..::.::;+=xxx+:.....:; :::....:;;;:::::;=xXXXx=;;::::::::::::::::::::;+;;;;;:. ...::::;;+=xxx=;:....::; :::....::;;;:::;+=xXXx=+;;::...:::::::::::::.::+;;;+;:....::++++==xxx=+;::.:::;+ ::::..:::;;:::::;+====+++;::....:::::::::::...:+;++++;:..:;+++==xxxx==;:::::::;+ ;:::::::::::....::;+++++++;:....:::::::::::..::+++==+;::::;++==xxXxx=;;:::::::;+ ;;;;;;;;:::.. .::;;+==+;::...::::::::::::::;++====+;:::;++==xxXx=+;::::::::;+ +++;;;;;;:::.. .::;====+;::..:::;;;:::::::;+==xx==;:::;;;++=xxx=+;;;;;:::::;+ +++++++;;;;;::.. ..:;==xx=+;:::::;;;;+++;;++==xxx==;:::::::;;++==+;;;;++;;;:::+
func Value2D ¶ added in v1.2.0
func Value2D[T Float, N Coord](x, y N, ns *NoiseState[T]) T
Value2D returns the noise value at the specified 2D position using the current *NoiseState settings.
The x and y parameters can be float32, float64, or int. Both coordinates must be the same type.
Return values are always normalized and in the range of -1.0 and 1.0.
Example ¶
package main
import (
"fmt"
"github.com/setanarut/fastnoise"
)
func main() {
chars := " .:;+=xX$"
noiseState := fastnoise.NewNoiseState[float32]()
noiseState.Frequency = 0.05
for y := range 10 {
for x := range 80 {
v := fastnoise.Value2D(x, y, noiseState)
i := int((v + 1) / 2 * float32(len(chars)))
fmt.Print(string(chars[i]))
}
fmt.Println()
}
}
Output: +=xxxxx==+++++=xXX$$XXx+;::..::;;++;:.. .:;+==xXXX$$$$$Xx=+:. .:;=xXXXx=+;;:. =xXXXXXx==+++==xXXXXXx=+;:.....::;::.. .:;+=xXXX$$$$$XXx=;:.. .:+=xXXxx=++;:. xXX$$$XXx==++==xxXXxx=+;:. ...::.. .:;=xXX$$$$$$XXxx=;:....:;+=xXXxx==+;:. XX$$$$$Xxx======xxxx=+;::. ...... ..;+=xX$$$$$XXXXx=+;::.::;+=xXXXXx==+;:. X$$$$$$XXx===++=====++;::.. ....... ..:;+xX$$$$$XXXXxx=++;:::;+=xXXXXXx==+;:. X$$$$$$XXxx=++++++++++;;::.......:......:;+=xX$$$$$XXXxxx==+;;;;+=xXX$XXXx=++;:. XX$$$$$$Xxx=++;;;;;;+++;;;;::::::::::..::;+=xX$$$$XXXXXxxx==+++==xX$$$$Xxx=+;::. xxXX$$$$XXx=+;;::::;;+++++++;;;;;;;:::::;++=xX$$$XXXXXXXXxx=====xX$$$$XXx=++;::. +=xXX$$$$Xx=+;::..:;;+========++++;;;::;;++=xXXXXXXxxXXXXXXxxxxxXX$$$XXx=++;;:.. ;+=xX$$$$Xx=+;:...::;+=xxxxxxxx==++;;:::;++=xxXXxxxxxXXX$$XXXXXXXXXXXXx=+;;:::..
func Value3D ¶ added in v1.2.0
func Value3D[T Float, N Coord](x, y, z N, ns *NoiseState[T]) T
Value3D returns the noise value at the specified 3D position using the current NoiseState settings.
The x, y, and z parameters can be float32, float64, or int. All coordinates must be the same type.
Returns a noise value normalized in the range of -1.0 and 1.0.
Example ¶
package main
import (
"fmt"
"github.com/setanarut/fastnoise"
)
func main() {
chars := " .:;+=xX$"
noiseState := fastnoise.NewNoiseState[float32]()
noiseState.Frequency = 0.05
for y := range 10 {
for x := range 80 {
v := fastnoise.Value3D(34, x, y, noiseState)
i := int((v + 1) / 2 * float32(len(chars)))
fmt.Print(string(chars[i]))
}
fmt.Println()
}
}
Output: XXXXXXXXx==++;;;;;;;;;;;;;++;;;:::::::;;;;++;;::......::;++===x====++;;;;;;++=xX XXXX$$XXXxx=+++;;;;;;;;;;++++;;;;:::;;;;+++++;;;::::::::;++==xxx===++;;;;;;+==xx XX$$$$$$XXxx==++++++++++++++++;;;;;;;;;+++++++;;;;;;;;;;;+==xxxxx==++;;;;;;+==xx XX$$$$$$$XXx===+++++++++++++++;;;;;;;+++++++++++++++++++++==xxxxx==++;;;;;;++=xx XX$$$$$$$XXxx===========++++++;;;;;+++++++++++++++++++++++==xxxxx==++;;;;;;++==x xXX$$$$$$XXxx===========++++;;;;;;+++++=++++++=============xxxxxxx=++;;;;;;++=== xXX$$$$$XXxxxx=====xx===+++;;;;;;+++======++====xxxxxxxxx===xxxxxx==++;;;;;+++== xxXXXXXXXXxxxxxxxxxxxx==++;;;:;;;;++===========xxxXXXXXxxx==xxxxxx==++;;;;;+++++ =xxxXXXXxxxxxxxxxxxxx===+;;:::::;;+====x======xxxXXXXXXXxxxxxxxxxx==++++;;;+++++ +==xxxxxxxxxxxxxxxxxx==++;::::::;;+==xxxxx===xxxXX$$$$XXXxxxxxxxxx==++++++++;;;;
Types ¶
type CellularDistanceFunc ¶
type CellularDistanceFunc int
CellularDistanceFunc describes the method for cellular distance functions.
const ( CellularDistanceEuclidean CellularDistanceFunc = iota CellularDistanceEuclideanSq CellularDistanceManhattan CellularDistanceHybrid )
type CellularReturnType ¶
type CellularReturnType int
CellularReturnType describes the return type for cellular distance noise.
const ( CellularReturnCellValue CellularReturnType = iota CellularReturnDistance CellularReturnDistance2 CellularReturnDistance2Add CellularReturnDistance2Sub CellularReturnDistance2Mul CellularReturnDistance2Div )
type DomainWarpType ¶
type DomainWarpType int
DomainWarpType describes the method used for domain warps.
const ( DomainWarpOpenSimplex2 DomainWarpType = iota DomainWarpOpenSimplex2Reduced DomainWarpBasicGrid )
type FractalType ¶
type FractalType int
FractalType describes the fractal method for fractal noise types.
const ( FractalNone FractalType = iota FractalFBm FractalRidged FractalPingPong FractalDomainWarpProgressive FractalDomainWarpIndependent )
type NoiseState ¶ added in v1.2.0
type NoiseState[T Float] struct { // Seed for noise. // // Default: 1337 Seed int // Noise frequency. // // Default: 0.01 Frequency T // RotationType3D specified the type of rotation applied to 3D noise. // // Default: RotationNone RotationType3D RotationType3D // Octaves is the number of octaves used for all fractal noise types. // // Default: 3 Octaves int // Lacunarity is the octave Lacunarity. // // Default: 2.0 Lacunarity T // Gain is the octave gain. // // Default: 0.5 Gain T // WeightedStrength is the octave weighting for all non-domain warp fractal types. // // Default: 0.0 WeightedStrength T // PingPongStrength is the strength of the fractal ping pong effect. // // Default: 2.0 PingPongStrength T // CellularDistanceFunc specifies the distance function used in cellular noise calculations. // // Default: CellularDistanceEuclideanSq, CellularDistanceFunc CellularDistanceFunc // CellularReturnType specifies the cellular return type from cellular noise calculations. // // Default: CellularReturnDistance, CellularReturnType CellularReturnType // CellularJitterMod is the maximum distance a cellular point can move from it's grid position. // Setting this higher than 1 will cause artifacts. // // Default: 1.0 CellularJitterMod T // DomainWarpType specifies the algorithm when using DomainWarp2D or DomainWarp3D. // // Default: DomainWarpOpenSimplex2 DomainWarpType DomainWarpType // DomainWarpAmp is the maximum warp distance from original position when using DomainWarp2D // or DomainWarp3D. // // Default: 1.0 DomainWarpAmp T // contains filtered or unexported fields }
NoiseState contains the configuration for generating a noise. This should only be created with NewNoiseState, as it will initialize with sane defaults, including any private members.
May be used to generate either float32 or float64 values.
func NewNoiseState ¶ added in v1.2.0
func NewNoiseState[T Float]() *NoiseState[T]
NewNoiseState initializes a new noise generator state with default values. This function must be used to create new states.
func (*NoiseState[T]) SetFractalType ¶ added in v1.2.0
func (state *NoiseState[T]) SetFractalType(ft FractalType)
SetFractalType specifies the method used for combining octaves for all fractal noise types. Only effects DomainWarp2D and DomainWarp3D functions.
Default: FractalNone
func (*NoiseState[T]) SetNoiseType ¶ added in v1.2.0
func (state *NoiseState[T]) SetNoiseType(nt NoiseType)
SetNoiseType specifies the noise algorithm.
Default: OpenSimplex2
type RotationType3D ¶
type RotationType3D int
RotationType3D describes a rotation method to apply to 3D noise.
const ( RotationNone RotationType3D = iota RotationImproveXYPlanes RotationImproveXZPlanes )