opensimplex

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: Unlicense Imports: 1 Imported by: 78

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

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)
	}
}
Output:

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
}

A seeded 64-bit noise instance

func New

func New(seed int64) Noise

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

func NewNormalized

func NewNormalized(seed int64) Noise

Construct 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
}

A seeded 32-bit noise instance

func New32

func New32(seed int64) Noise32

Construct 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

Construct 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