opensimplex

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: Unlicense Imports: 1 Imported by: 0

README

OpenSimplex in Go

GoDoc Build Status

OpenSimplex noise is a random noise algorithm by Kurt Spencer, made as a patent-free alternative to Perlin and Simplex noise. This Go port is based on Kurt's Java implementation.

For an introduction to OpenSimplex noise, see Kurt Spencer's post announcing it. If you're not familiar with random noise, the Wikipedia post on Perlin noise is a good introduction.

Why not Perlin noise?

As Kurt explains in his post, Perlin noise tends to generate noise with noticeable axis-aligned artifacts. Simplex noise fixes these artifacts, but it's patented. OpenSimplex noise is for people who don't want to deal with Simplex's patent.

The difference between Perlin and OpenSimplex noise is easiest to see in pictures. This is Perlin noise, with a noticeable bias towards vertical and horizontal artifacts:

Perlin Noise sample

Here's what OpenSimplex noise looks like:

OpenSimplex Noise sample

Tests

This implementation of OpenSimplex's tests verify its output against the output of the reference Java implementation. I haven't run these tests on different architectures, so results may vary.

License

This code is under the same "license" as Kurt's OpenSimplex - the public domain "unlicense."

Next Steps

  • More documentation
  • Benchmarks

Documentation

Overview

Package opensimplex is a Go implementation of Kurt Spencer's patent-free alternative to Perlin and Simplex noise.

Given a seed, it generates smoothly-changing deterministic random values in 2, 3 or 4 dimensions. It's commonly used for procedurally generated images, geometry, or other randomly-influenced applications that require a random gradient.

For more information on OpenSimplex noise, read more from the creator of the algorithm: http://uniblock.tumblr.com/post/97868843242/noise

Example
noise := New(rand.Int63())

w, h := 100, 100
heightmap := make([]float64, w*h)
for y := 0; y < h; y++ {
	for x := 0; x < w; x++ {
		xFloat := float64(x) / float64(w)
		yFloat := float64(y) / float64(h)
		heightmap[(y*w)+x] = noise.Eval2(xFloat, yFloat)
	}
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Noise

type Noise interface {
	Eval2(x, y float64) float64
	Eval3(x, y, z float64) float64
	Eval4(x, y, z, w float64) float64
}

Noise presents an interface for accessing a seeded noise generator in 2, 3, or 4 dimensions

func New

func New(seed int64) Noise

New constructs a Noise instance with a 64-bit seed. Two Noise instances with the same seed will have the same output.

func NewFbmNoise

func NewFbmNoise(source Noise, octaves int, frequency, persistence, lacunarity float64) Noise

NewFbmNoise creates a new FBM Noise function using an input Noise interface.

- octaves are the number of times to apply the noise function - frequency is the frequency with which to sample the source noise - higher frequency means faster rate of change - lacunarity is a multiplier for frequency applied at each octave - persistence is a multiplier for amplitude applied at each octave

**NOTE**: It is not recommended to use normalized noise, since application of octaves has the potential to squeeze the output beyond the [0-1) range. If you need normalized FBM noise, your options are limited:

- Save your noise data and normalize after generation - Run observations on a large data set of points to determine the min and max values, then normalize as you sample

func NewNormalized

func NewNormalized(seed int64) Noise

NewNormalized constructs a normalized Noise instance with a 64-bit seed. Eval methods will return values in [0, 1). Two Noise instances with the same seed will have the same output.

type Noise32

type Noise32 interface {
	Eval2(x, y float32) float32
	Eval3(x, y, z float32) float32
	Eval4(x, y, z, w float32) float32
}

Noise32 presents an interface for accessing a seeded 32-bit noise generator in 2, 3, or 4 dimensions

func New32

func New32(seed int64) Noise32

New32 constructs a Noise32 instance with a 64-bit seed. Two Noise32 instances with the same seed will have the same output.

func NewNormalized32

func NewNormalized32(seed int64) Noise32

NewNormalized32 constructs a normalized Noise32 instance with a 64-bit seed. Eval methods will return values in [0, 1). Two Noise32 instances with the same seed will have the same output.

Jump to

Keyboard shortcuts

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