noiselib

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: GPL-2.0 Imports: 6 Imported by: 0

README

noiselib

An implementation of libnoise in Go

Goals

The goal of this library is to provide a complete reimplementation of http://libnoise.sourceforge.net/ in Go. It should be functionally equivilent, and provide very similar outputs as compared to the original.

Progress

All noise sources have been implemented, as well as the noise utils, for easier access to terrain style output, as well as following the tutorials in the original site. Bugfixes are to come.

Documentation

Index

Constants

View Source
const (
	QualitySTD  = 0
	QualityFAST = 1
	QualityBEST = 2
)
View Source
const (
	AbsModuleCount        = 1
	AddModuleCount        = 2
	BillowModuleCount     = 0
	BlendModuleCount      = 3
	ClampModuleCount      = 1
	DisplaceModuleCount   = 4
	ExponentModuleCount   = 1
	InvertModuleCount     = 1
	PowerModuleCount      = 2
	RotateModuleCount     = 1
	ScaleBiasModuleCount  = 1
	ScalePointModuleCount = 1
	SelectModuleCount     = 3
	TerraceModuleCount    = 1
	TurbulenceModuleCount = 1
)
View Source
const (
	XNoiseGen     = 1619
	YNoiseGen     = 31337
	ZNoiseGen     = 6971
	SeedNoiseGen  = 1013
	ShiftNoiseGen = 8
)
View Source
const (
	DefaultPerlinFrequency   = 1.0
	DefaultPerlinLacunarity  = 2.0
	DefaultPerlinOctaveCount = 6
	DefaultPerlinPersistence = 0.5
	DefaultPerlinQuality     = QualitySTD
	DefaultPerlinSeed        = 0
	PerlinMaxOctave          = 30
)
View Source
const (
	DefaultRidgedFrequency      = 1.0
	DefaultRidgedLacunarity     = 2.0
	DefaultRidgedOctaveCount    = 6
	DefaultRidgedQuality        = QualitySTD
	DefaultRidgedSeed           = 0
	RidgedMaxOctave             = 30
	DefaultRidgedSpectralWeight = 1.0
	DefaultRidgedOffset         = 1.0
	DefaultRidgedGain           = 2.0
)
View Source
const (
	DefaultRotateX = 0.0
	DefaultRotateY = 0.0
	DefaultRotateZ = 0.0
	DegToRad       = math.Pi / 180
)
View Source
const (
	DefaultBias  = 0.0
	DefaultScale = 1.0
)
View Source
const (
	DefaultScalePointX = 1.0
	DefaultScalePointY = 1.0
	DefaultScalePointZ = 1.0
)
View Source
const (
	DefaultTurbulenceFrequency = DefaultPerlinFrequency
	DefaultTurbulencePower     = 1.0
	DefaultTurbulenceRoughness = 3
	DefaultTurbulenceSeed      = DefaultPerlinSeed
)
View Source
const (
	DefaultVoronoiDisplacement = 1.0
	DefaultVoronoiFrequency    = 1.0
	DefaultVoronoiSeed         = 0
)
View Source
const DefaultBillowFrequency = float64(1)
View Source
const DefaultBillowLacunarity = float64(2)
View Source
const DefaultBillowMaxOctave = 30
View Source
const DefaultBillowOctaveCount = 6
View Source
const DefaultBillowPersistence = float64(0.5)
View Source
const DefaultBillowQuality = QualitySTD
View Source
const DefaultBillowSeed = 0
View Source
const DefaultClampLowerBound = -1.0
View Source
const DefaultClampUpperBound = 1.0
View Source
const DefaultCylinderFrequency = 1.0
View Source
const DefaultExp = 1.0
View Source
const DefaultSelectEdgeFalloff = 0.0
View Source
const DefaultSelectLowerBound = -1.0
View Source
const DefaultSelectUpperBound = 1.0
View Source
const DefaultSphereFrequency = 1.0
View Source
const SQRT_2 = 1.4142135623730951
View Source
const SQRT_3 = 1.7320508075688772

Variables

View Source
var RandomVectors = []float64{}/* 1024 elements not displayed */

Really should be a constant, but no constant arrays in Go

Functions

func BlendChannel

func BlendChannel(channel0, channel1 uint8, alpha float64) uint8

func ClampValue

func ClampValue(value, lowerBound, upperBound int) int

func ClampValueFloat

func ClampValueFloat(value, lowerBound, upperBound float64) float64

func CubicInterp

func CubicInterp(n0, n1, n2, n3, a float64) float64

Performs a cubic interpolation between two values bound between two other values.

func GradientCoherentNoise3D

func GradientCoherentNoise3D(x, y, z float64, seed, quality int) float64

func GradientNoise3D

func GradientNoise3D(fx, fy, fz, ix, iy, iz float64, seed int) float64

func IntValueNoise3D

func IntValueNoise3D(x, y, z, seed int) int

func LinearInterp

func LinearInterp(n0, n1, a float64) float64

Performs a linear interpolation between two values

func LinearInterpColor

func LinearInterpColor(color0, color1 color.RGBA, alpha float64) color.RGBA

func MakeMap

func MakeMap(width, height int) [][]float64

func MapToCylinder

func MapToCylinder(angle, height float64, source Module) float64

func MapToLine

func MapToLine(sx, sy, sz, ex, ey, ez, p float64, attenuate bool, source Module) float64

func MapToPlane

func MapToPlane(x, y float64, source Module) float64

func MapToSphere

func MapToSphere(lat, lon float64, source Module) float64

func NoiseMapCylinder

func NoiseMapCylinder(lowerAngleBound, upperAngleBound,
	lowerHeightBound, upperHeightBound float64,
	width, height int, source Module) [][]float64

func NoiseMapPlane

func NoiseMapPlane(lowerXBound, upperXBound, lowerZBound, upperZBound float64,
	width, height int, seamless bool, source Module) [][]float64

func NoiseMapSphere

func NoiseMapSphere(eastBound, westBound, northBound, southBound float64,
	width, height int, source Module) [][]float64

func SCurve3

func SCurve3(a float64) float64

Maps a value onto a cubic S-curve

func SCurve5

func SCurve5(a float64) float64

Maps a value onto a quintic S-curve.

func ValueCoherentNoise3D

func ValueCoherentNoise3D(x, y, z float64, seed, quality int) float64

func ValueNoise3D

func ValueNoise3D(x, y, z, seed int) float64

Types

type Abs

type Abs struct {
	SourceModule []Module
}

func (Abs) GetSourceModule

func (a Abs) GetSourceModule(index int) Module

func (Abs) GetValue

func (a Abs) GetValue(x, y, z float64) float64

func (Abs) SetSourceModule

func (a Abs) SetSourceModule(index int, source Module)

type Add

type Add struct {
	SourceModule []Module
}

func (Add) GetSourceModule

func (a Add) GetSourceModule(index int) Module

func (Add) GetValue

func (a Add) GetValue(x, y, z float64) float64

func (Add) SetSourceModule

func (a Add) SetSourceModule(index int, source Module)

type Billow

type Billow struct {
	SourceModule                       []Module
	Frequency, Lacunarity, Persistence float64
	Seed, Quality, OctaveCount         int
}

func DefaultBillow

func DefaultBillow() Billow

func (Billow) GetSourceModule

func (b Billow) GetSourceModule(index int) Module

func (Billow) GetValue

func (b Billow) GetValue(x, y, z float64) float64

func (Billow) SetSourceModule

func (b Billow) SetSourceModule(index int, module Module)

type Blend

type Blend struct {
	SourceModule []Module
}

func (Blend) GetSourceModule

func (b Blend) GetSourceModule(index int) Module

func (Blend) GetValue

func (b Blend) GetValue(x, y, z float64) float64

func (Blend) SetSourceModule

func (b Blend) SetSourceModule(index int, sourceModule Module)

type Checkerboard

type Checkerboard struct{}

func (Checkerboard) GetSourceModule

func (c Checkerboard) GetSourceModule(index int) Module

func (Checkerboard) GetValue

func (c Checkerboard) GetValue(x, y, z float64) float64

func (Checkerboard) SetSourceModule

func (c Checkerboard) SetSourceModule(index int, sourceModule Module)

type Clamp

type Clamp struct {
	SourceModule           []Module
	LowerBound, UpperBound float64
}

func DefaultClamp

func DefaultClamp(module Module) *Clamp

func (Clamp) GetSourceModule

func (c Clamp) GetSourceModule(index int) Module

func (Clamp) GetValue

func (c Clamp) GetValue(x, y, z float64) float64

func (*Clamp) SetBounds

func (c *Clamp) SetBounds(lowerBound, upperBound float64)

func (Clamp) SetSourceModule

func (c Clamp) SetSourceModule(index int, sourceModule Module)

type Constant

type Constant struct {
	Value float64
}

func (Constant) GetSourceModule

func (c Constant) GetSourceModule(index int) Module

func (Constant) GetSourceModuleCount

func (c Constant) GetSourceModuleCount() int

func (Constant) GetValue

func (c Constant) GetValue(x, y, z float64) float64

func (Constant) NewModule

func (c Constant) NewModule() Constant

func (Constant) SetSourceModule

func (c Constant) SetSourceModule(index int, sourceModule Module)

type Curve

type Curve struct {
	ControlPoints map[float64]float64
	SourceModule  []Module
}

func (*Curve) AddControlPoint

func (c *Curve) AddControlPoint(inputValue, outputValue float64)

func (*Curve) ClearAllControlPoints

func (c *Curve) ClearAllControlPoints()

func (Curve) GetSourceModule

func (c Curve) GetSourceModule(index int) Module

func (Curve) GetValue

func (c Curve) GetValue(x, y, z float64) float64

func (Curve) SetSourceModule

func (c Curve) SetSourceModule(index int, sourceModule Module)

type Cylinders

type Cylinders struct {
	Frequency float64
}

func DefaultCylinders

func DefaultCylinders() Cylinders

func (Cylinders) GetSourceModule

func (c Cylinders) GetSourceModule(index int) Module

func (Cylinders) GetValue

func (c Cylinders) GetValue(x, y, z float64) float64

func (Cylinders) SetSourceModule

func (c Cylinders) SetSourceModule(index int, sourceModule Module)

type Displace

type Displace struct {
	SourceModule []Module
}

func (Displace) GetSourceModule

func (d Displace) GetSourceModule(index int) Module

func (Displace) GetValue

func (d Displace) GetValue(x, y, z float64) float64

func (Displace) SetSourceModule

func (d Displace) SetSourceModule(index int, sourceModule Module)

func (Displace) SetXDisplaceModule

func (d Displace) SetXDisplaceModule(source Module)

func (Displace) SetXYZDisplaceModule

func (d Displace) SetXYZDisplaceModule(sourceX, sourceY, sourceZ Module)

func (Displace) SetYDisplaceModule

func (d Displace) SetYDisplaceModule(source Module)

func (Displace) SetZDisplaceModule

func (d Displace) SetZDisplaceModule(source Module)

type Exponent

type Exponent struct {
	SourceModule []Module
	Exponent     float64
}

func DefaultExponent

func DefaultExponent() Exponent

func (Exponent) GetSourceModule

func (e Exponent) GetSourceModule(index int) Module

func (Exponent) GetValue

func (e Exponent) GetValue(x, y, z float64) float64

func (Exponent) SetSourceModule

func (e Exponent) SetSourceModule(index int, source Module)

type GradientColor

type GradientColor struct {
	GradientPoints map[float64]color.RGBA
}

func (*GradientColor) AddGradientPoint

func (g *GradientColor) AddGradientPoint(position float64, color color.RGBA)

func (*GradientColor) ClearGradient

func (g *GradientColor) ClearGradient()

func (*GradientColor) GetColor

func (g *GradientColor) GetColor(position float64) color.RGBA

type Invert

type Invert struct {
	SourceModule []Module
}

func (Invert) GetSourceModule

func (i Invert) GetSourceModule(index int) Module

func (Invert) GetValue

func (i Invert) GetValue(x, y, z float64) float64

func (Invert) SetSourceModule

func (i Invert) SetSourceModule(index int, source Module)

type Max

type Max struct {
	SourceModule []Module
}

func (Max) GetSourceModule

func (m Max) GetSourceModule(index int) Module

func (Max) GetValue

func (m Max) GetValue(x, y, z float64) float64

func (Max) SetSourceModule

func (m Max) SetSourceModule(index int, source Module)

type Min

type Min struct {
	SourceModule []Module
}

func (Min) GetSourceModule

func (m Min) GetSourceModule(index int) Module

func (Min) GetValue

func (m Min) GetValue(x, y, z float64) float64

func (Min) SetSourceModule

func (m Min) SetSourceModule(index int, source Module)

type Module

type Module interface {

	//Returns a source module connected to thise noise module.
	GetSourceModule(index int) Module

	//Generates an output value given the coordinates of the specified input
	// value. Before an applicaion can call this method, it must first connect
	// all required source modules via SetSourceModule(). If these source modules
	// are not connected to this module, this method raises an error.
	GetValue(x, y, z float64) float64

	//Sets a source module in the given index.
	SetSourceModule(index int, sourceModule Module)
}

type Multiply

type Multiply struct {
	SourceModule []Module
}

func (Multiply) GetSourceModule

func (m Multiply) GetSourceModule(index int) Module

func (Multiply) GetValue

func (m Multiply) GetValue(x, y, z float64) float64

func (Multiply) SetSourceModule

func (m Multiply) SetSourceModule(index int, source Module)

type Perlin

type Perlin struct {
	Frequency, Lacunarity, Persistence float64
	OctaveCount, Quality, Seed         int
}

func DefaultPerlin

func DefaultPerlin() Perlin

func (Perlin) GetSourceModule

func (p Perlin) GetSourceModule(index int) Module

func (Perlin) GetValue

func (p Perlin) GetValue(x, y, z float64) float64

func (*Perlin) SetOctaveCount

func (p *Perlin) SetOctaveCount(octave int)

SetOctaveCount sets the number of octaves performed in the noise calculation. Automatically clamps the given value to [1, PerlinMaxOctave].

func (Perlin) SetSourceModule

func (p Perlin) SetSourceModule(index int, source Module)

type Power

type Power struct {
	SourceModule []Module
}

func (Power) GetSourceModule

func (m Power) GetSourceModule(index int) Module

func (Power) GetValue

func (m Power) GetValue(x, y, z float64) float64

func (Power) SetSourceModule

func (m Power) SetSourceModule(index int, source Module)

type RenderImage

type RenderImage struct {
	CosAzimuth, CosElev, SinAzimuth, SinElev     float64
	LightAzimuth, LightBrightness, LightContrast float64
	LightElev, LightIntensity                    float64
	Gradient                                     GradientColor
	LightEnabled, WrapEnabled, RecalculateLight  bool
	LightColor                                   color.RGBA
	BackgroundImage                              image.RGBA
	DestinationImage                             image.RGBA
	NoiseMap                                     [][]float64
}

func (*RenderImage) BuildGrayscaleGradient

func (r *RenderImage) BuildGrayscaleGradient()

func (*RenderImage) BuildTerrainGradient

func (r *RenderImage) BuildTerrainGradient()

func (*RenderImage) Render

func (r *RenderImage) Render()

func (*RenderImage) RenderFile

func (r *RenderImage) RenderFile(filename string)

func (*RenderImage) SetLightAzimuth

func (r *RenderImage) SetLightAzimuth(azimuth float64)

func (*RenderImage) SetLightBrightness

func (r *RenderImage) SetLightBrightness(brightness float64)

func (*RenderImage) SetLightContrast

func (r *RenderImage) SetLightContrast(contrast float64)

func (*RenderImage) SetLightElev

func (r *RenderImage) SetLightElev(elev float64)

func (*RenderImage) SetLightIntensity

func (r *RenderImage) SetLightIntensity(intensity float64)

type Ridgedmulti

type Ridgedmulti struct {
	Frequency, Lacunarity, SpectralWeight, Offset, Gain float64
	OctaveCount, Quality, Seed                          int
	SpectralWeights                                     []float64
}

func DefaultRidgedmulti

func DefaultRidgedmulti() Ridgedmulti

func (Ridgedmulti) CalcSpectralWeights

func (r Ridgedmulti) CalcSpectralWeights()

func (Ridgedmulti) GetSourceModule

func (r Ridgedmulti) GetSourceModule(index int) Module

func (Ridgedmulti) GetValue

func (r Ridgedmulti) GetValue(x, y, z float64) float64

func (*Ridgedmulti) SetOctaveCount

func (r *Ridgedmulti) SetOctaveCount(octave int)

SetOctaveCount sets the number of octaves performed in the noise calculation. Automatically clamps the given value to [1, PerlinMaxOctave].

func (Ridgedmulti) SetSourceModule

func (r Ridgedmulti) SetSourceModule(index int, source Module)

type Rotatepoint

type Rotatepoint struct {
	X1Matrix, X2Matrix, X3Matrix float64
	Y1Matrix, Y2Matrix, Y3Matrix float64
	Z1Matrix, Z2Matrix, Z3Matrix float64
	XAngle, YAngle, ZAngle       float64
	SourceModule                 []Module
}

func DefaultRotatepoint

func DefaultRotatepoint() Rotatepoint

func (Rotatepoint) GetSourceModule

func (r Rotatepoint) GetSourceModule(index int) Module

func (Rotatepoint) GetValue

func (r Rotatepoint) GetValue(x, y, z float64) float64

func (*Rotatepoint) SetAngles

func (r *Rotatepoint) SetAngles(xAngle, yAngle, zAngle float64)

func (Rotatepoint) SetSourceModule

func (r Rotatepoint) SetSourceModule(index int, source Module)

func (*Rotatepoint) SetXAngle

func (r *Rotatepoint) SetXAngle(xAngle float64)

func (*Rotatepoint) SetYAngle

func (r *Rotatepoint) SetYAngle(yAngle float64)

func (*Rotatepoint) SetZAngle

func (r *Rotatepoint) SetZAngle(zAngle float64)

type ScaleBias

type ScaleBias struct {
	SourceModule []Module
	Bias, Scale  float64
}

func DefaultScaleBias

func DefaultScaleBias() ScaleBias

func (ScaleBias) GetSourceModule

func (a ScaleBias) GetSourceModule(index int) Module

func (ScaleBias) GetValue

func (a ScaleBias) GetValue(x, y, z float64) float64

func (ScaleBias) SetSourceModule

func (a ScaleBias) SetSourceModule(index int, source Module)

type ScalePoint

type ScalePoint struct {
	SourceModule           []Module
	XScale, YScale, ZScale float64
}

func DefaultScalePoint

func DefaultScalePoint() ScalePoint

func (ScalePoint) GetSourceModule

func (a ScalePoint) GetSourceModule(index int) Module

func (ScalePoint) GetValue

func (a ScalePoint) GetValue(x, y, z float64) float64

func (ScalePoint) SetSourceModule

func (a ScalePoint) SetSourceModule(index int, source Module)

type Select

type Select struct {
	SourceModule                        []Module
	LowerBound, UpperBound, EdgeFalloff float64
}

func DefaultSelect

func DefaultSelect() Select

func (Select) GetSourceModule

func (s Select) GetSourceModule(index int) Module

func (Select) GetValue

func (s Select) GetValue(x, y, z float64) float64

func (*Select) SetBounds

func (s *Select) SetBounds(lowerBound, upperBound float64)

func (*Select) SetEdgeFalloff

func (s *Select) SetEdgeFalloff(edgeFalloff float64)

func (Select) SetSourceModule

func (s Select) SetSourceModule(index int, source Module)

type Spheres

type Spheres struct {
	Frequency float64
}

func DefaultSpheres

func DefaultSpheres() Spheres

func (Spheres) GetSourceModule

func (s Spheres) GetSourceModule(index int) Module

func (Spheres) GetValue

func (s Spheres) GetValue(x, y, z float64) float64

func (Spheres) SetSourceModule

func (s Spheres) SetSourceModule(index int, source Module)

type Terrace

type Terrace struct {
	InvertTerraces bool
	ControlPoints  []float64
	SourceModule   []Module
}

func DefaultTerrace

func DefaultTerrace() Terrace

func (Terrace) AddControlPoint

func (t Terrace) AddControlPoint(value float64)

func (Terrace) ClearAllControlPoints

func (t Terrace) ClearAllControlPoints()

func (Terrace) GetSourceModule

func (t Terrace) GetSourceModule(index int) Module

func (Terrace) GetValue

func (t Terrace) GetValue(x, y, z float64) float64

func (Terrace) MakeControlPoints

func (t Terrace) MakeControlPoints(count int)

func (Terrace) SetSourceModule

func (t Terrace) SetSourceModule(index int, source Module)

type TranslatePoint

type TranslatePoint struct {
	SourceModule                       []Module
	XTranslate, YTranslate, ZTranslate float64
}

func (TranslatePoint) GetSourceModule

func (t TranslatePoint) GetSourceModule(index int) Module

func (TranslatePoint) GetValue

func (t TranslatePoint) GetValue(x, y, z float64) float64

func (TranslatePoint) SetSourceModule

func (t TranslatePoint) SetSourceModule(index int, source Module)

func (*TranslatePoint) SetTranslatePoints

func (t *TranslatePoint) SetTranslatePoints(x, y, z float64)

type Turbulence

type Turbulence struct {
	Power                                          float64
	XDistortModule, YDistortModule, ZDistortModule Perlin
	SourceModules                                  []Module
}

func DefaultTurbulence

func DefaultTurbulence() Turbulence

func (Turbulence) GetSourceModule

func (t Turbulence) GetSourceModule(index int) Module

func (Turbulence) GetValue

func (t Turbulence) GetValue(x, y, z float64) float64

func (*Turbulence) SetFrequency

func (t *Turbulence) SetFrequency(frequency float64)

func (*Turbulence) SetRoughness

func (t *Turbulence) SetRoughness(roughness int)

func (*Turbulence) SetSeed

func (t *Turbulence) SetSeed(seed int)

func (Turbulence) SetSourceModule

func (t Turbulence) SetSourceModule(index int, source Module)

type Voronoi

type Voronoi struct {
	Displacement, Frequency float64
	EnableDistance          bool
	Seed                    int
}

func DefaultVoronoi

func DefaultVoronoi() Voronoi

func (Voronoi) GetSourceModule

func (v Voronoi) GetSourceModule(index int) Module

func (Voronoi) GetValue

func (v Voronoi) GetValue(x, y, z float64) float64

func (Voronoi) SetSourceModule

func (v Voronoi) SetSourceModule(index int, source Module)

Jump to

Keyboard shortcuts

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