rand

package
v0.0.0-...-8385335 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: Unlicense Imports: 6 Imported by: 3

Documentation

Overview

Package rand provides random number functions that are missing in the standard library, as well as other forms of random numbers such as proceedural noise (eg Perlin noise)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CellNoiseSlow

func CellNoiseSlow(lambda, max int, dist data.DistanceMetric) func(x, y float64) float64

CellNoiseSlow creates a function which gives 2D cell noise. Lambda and max determine the number of feature points in a given unit cube, which lambda is the average number per cell and max is the maximum number per cell. DistanceMetric dist provides the notion of 'distance'.

func FillPermutation

func FillPermutation(seed int64)

FillPermutation changes the permutation table used for noise generation. If a source is provided, it uses that. Otherwise, it uses a source seeded with the time.Now().UnixNano().

func Float64NM

func Float64NM(low, high float64) float64

Float64NM produced a random float64 in the range [low,high) from the standard source. Assumes source is already seeded. Panics if low >= high.

func IntNM

func IntNM(low, high int) int

IntNM produced a random int in the range [low,high) from the standard source. Assumes source is already seeded. Panics if low >= high.

func MakeNoisePoints2D

func MakeNoisePoints2D(xrange, yrange [2]int, maxPtsPerCell int, cdf []float64, p *[512]int) []data.Interface

MakeNoisePoints2D generates all the points for all the cells given the parameters.

func MakeNoisePoints3D

func MakeNoisePoints3D(xrange, yrange, zrange [2]int, maxPtsPerCell int, cdf []float64, p *[512]int) []data.Interface

MakeNoisePoints3D generates all the points for all the cells given the parameters.

func MakePermutation

func MakePermutation(seed int64) (perm *[512]int)

MakePermutation makes a permutation table used in noise generation.

func Noise1

func Noise1(x float64) float64

Noise1 provides 1d noise based on Noise3.

func Noise2

func Noise2(x, y float64) float64

Noise2 provides 2d noise based on Noise3.

func Noise3

func Noise3(x, y, z float64) float64

Noise3 returns 3d perlin noise based on Ken Perlin's 2002 "improved noise" algorithm.

See: http://mrl.nyu.edu/~perlin/noise/ Paper: http://mrl.nyu.edu/~perlin/paper445.pdf

func Noise3Octaves

func Noise3Octaves(x, y, z float64, octaves int, lacunarity, persistence float64) float64

Noise3Octaves uses the idea of adding diffent samplings of perlin noise together to add a "fractal" quality to the detail of the noise produced.

octaves is the number of samples taken and added together, usually 3 or 4 is a good. lacunarity is the rate at which the frequency (space between samplings) increases, usually 2. persistence is the rate at which the amplitude (how much sample affects octave) decreases, usually 0.5.

See: http://flafla2.github.io/2014/08/09/perlinnoise.html and: http://freespace.virgin.net/hugo.elias/models/m_perlin.htm (may be broken)

Types

type CellNoise2D

type CellNoise2D struct {
	// contains filtered or unexported fields
}

CellNoise2D contains the configuration data for a 2D cell noise generator.

func NewCellNoise2D

func NewCellNoise2D(seed int64, lambda, maxPtsPerCell int, dist data.DistanceMetric) *CellNoise2D

NewCellNoise2D creates a pointer to a new CellNoise2D struct.

Lambda and max determine the number of feature points in a given unit cube, where lambda is the average number per cell and maxPtsPerCell is the maximum number per cell. DistanceMetric dist provides the notion of 'distance'.

func (*CellNoise2D) Noise

func (conf *CellNoise2D) Noise(x, y float64) float64

Noise gets a noise value at the given point (x, y).

type CellNoise3D

type CellNoise3D struct {
	// contains filtered or unexported fields
}

CellNoise3D contains the configuration data for a 3D cell noise generator.

func NewCellNoise3D

func NewCellNoise3D(seed int64, lambda, maxPtsPerCell int, dist data.DistanceMetric) *CellNoise3D

NewCellNoise3D creates a pointer to a new CellNoise3D struct.

Lambda and max determine the number of feature points in a given unit cube, where lambda is the average number per cell and maxPtsPerCell is the maximum number per cell. DistanceMetric dist provides the notion of 'distance'.

func (*CellNoise3D) Noise

func (conf *CellNoise3D) Noise(x, y, z float64) float64

Noise generates a noise value at the (x,y,z) location.

Directories

Path Synopsis
Package main is a simple demo of cell noise.
Package main is a simple demo of cell noise.
Package main is a simple visualization of perlin noise.
Package main is a simple visualization of perlin noise.

Jump to

Keyboard shortcuts

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