fastnoise

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2024 License: MIT Imports: 1 Imported by: 1

README

FastNoise Lite

Web Preview App

FastNoise Lite is an noise generation package with a large selection of noise algorithms.

Features

  • 2D & 3D sampling
  • OpenSimplex2 noise
  • OpenSimplex2S noise
  • Cellular (Voronoi) noise
  • Perlin noise
  • Value noise
  • Value Cubic noise
  • OpenSimplex2-based domain warp
  • Basic Grid Gradient domain warp
  • Multiple fractal options for all of the above
  • Supports floats and/or doubles

Getting Started

Here's an example for creating a 128x128 array of OpenSimplex2 noise

import "fastnoise"

// Create and configure noise state (either float32 or float64)
var noise = fastnoise.New[float32]()
noise.NoiseType(fastnoise.OpenSimplex2)

// Gather noise data
var noiseData [128][128]float32

for x := 0; x < 128; x++ {
	for y := 0; y < 128; y++ {
		noiseData[x][y] = noise.Noise2D(x, y)
	}
}

// Do something with this data...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 Float

type Float interface {
	float32 | float64
}

Float represents a floating-point number type.

type FractalType

type FractalType int

FractalType describes the fractal method for fractal noise types.

const (
	FractalNone FractalType = iota
	FractalFBm
	FractalRidged
	FractalPingPong
	FractalDomainWarpProgressive
	FractalDomainWarpIndependent
)

type NoiseType

type NoiseType int

NoiseType describes a noise algorithm.

const (
	OpenSimplex2 NoiseType = iota
	OpenSimplex2S
	Cellular
	Perlin
	ValueCubic
	Value
	TypeCount // The number of noise types
)

type RotationType3D

type RotationType3D int

RotationType3D describes a rotation method to apply to 3D noise.

const (
	RotationNone RotationType3D = iota
	RotationImproveXYPlanes
	RotationImproveXZPlanes
)

type State

type State[T Float] struct {
	// Seed for all noise types.
	//
	// Default: 1337
	Seed int
	// Frequency for all noise types.
	//
	// 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 for all fractal noise types.
	//
	// Default: 2.0
	Lacunarity T
	// Gain is the octave gain for all fractal noise types.
	//
	// 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
}

State contains the configuration for generating a noise. This should only be created with NewState, as it will initialize with sane defaults, including any private members.

May be used to generate either float32 or float64 values.

func New

func New[T Float]() *State[T]

New initializes a new noise generator state with default values. This function must be used to create new states.

func (*State[T]) DomainWarp2D

func (state *State[T]) DomainWarp2D(x, y T) (T, T)

DomainWarp2D warps the input position using current domain warp settings.

func (*State[T]) DomainWarp3D

func (state *State[T]) DomainWarp3D(x, y, z T) (T, T, T)

DomainWarp2D warps the input position using current domain warp settings.

func (*State[T]) FractalType

func (state *State[T]) FractalType(ft FractalType)

FractalType specifies the method used for combining octaves for all fractal noise types. Only effects DomainWarp2D and DomainWarp3D functions.

Default: FractalNone

func (*State[T]) GetNoise2D

func (state *State[T]) GetNoise2D(x, y T) T

GetNoise2D calculates the noise value at the specified 2D position using the current state settings.

Return values are always normalized and in the range of -1.0 and 1.0.

func (*State[T]) GetNoise3D

func (state *State[T]) GetNoise3D(x, y, z T) T

GetNoise3D calculates the noise value at the specified 3D position using the current state settings.

Return values are always normalized and in the range of -1.0 and 1.0.

func (*State[T]) Noise2D

func (state *State[T]) Noise2D(x, y int) T

GetNoise2D calculates the noise value at the specified 2D position using the current state settings.

This is a convenience function for GetNoise2D that accepts integral coordinates. Return values are always normalized and in the range of -1.0 and 1.0.

func (*State[T]) Noise3D

func (state *State[T]) Noise3D(x, y, z int) T

GetNoise3D calculates the noise value at the specified 3D position using the current state settings.

This is a convenience function for GetNoise3D that accepts integral coordinates. Return values are always normalized and in the range of -1.0 and 1.0.

func (*State[T]) NoiseType

func (state *State[T]) NoiseType(nt NoiseType)

NoiseType specifies the algorithm that will be used with GetNoise2D and GetNoise3D.

Default: OpenSimplex2

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL