noise

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 2 Imported by: 0

README

noise

import "github.com/vibrantgio/noise"

Package noise implements Perlin and Simplex noise functions.

Adapted from https://github.com/josephg/noisejs/blob/master/perlin.js

This code was placed in the public domain by its original author, Stefan Gustavson. You may use it as you see fit, but attribution is appreciated.

The code was converted code to Go. Note that the Go code uses a Simplex3D struct instead of a class, and the methods are defined on the struct. This is because Go does not support classes, and structs with associated methods are used to achieve similar functionality.

For coding assistants

Read the canonical guide before writing code against this module — the module inventory with current tags, the application skeleton, MVU and rx semantics, typography, and the pitfalls that are not guessable:

https://raw.githubusercontent.com/vibrantgio/workbench/master/llms.txt

AGENTS.md in this repository has the build and test commands, and — since nothing else in the organization says so — how to regenerate the four reference images the TestImage* tests compare against.

Documentation

Index

Constants

View Source
const F3 = 1.0 / 3.0
View Source
const G3 = 1.0 / 6.0

Variables

View Source
var F2 = 0.5 * (math.Sqrt(3) - 1.0)
View Source
var G2 = (3.0 - math.Sqrt(3)) / 6.0
View Source
var PERMUTATIONS = [...]uint8{}/* 256 elements not displayed */

To remove the need for index wrapping, double the permutation table length

Functions

This section is empty.

Types

type Perlin2D

type Perlin2D struct {
	Permutations
}

func NewPerlin2D

func NewPerlin2D(seed float64) *Perlin2D

func (*Perlin2D) Noise

func (n *Perlin2D) Noise(x, y float64) float64

type Perlin3D

type Perlin3D struct {
	Permutations
}

func NewPerlin3D

func NewPerlin3D(seed float64) *Perlin3D

Seed the noise functions. Only 65536 different seeds are supported. Use a float between 0 and 1 or an integer from 1 to 65536.

func (*Perlin3D) Noise

func (n *Perlin3D) Noise(x, y, z float64) float64

type Permutations

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

func (*Permutations) Seed

func (s *Permutations) Seed(seed uint16)

Seed the noise functions. Only 65536 different seeds are supported. Use a an integer from 1 to 65536. This isn't a very good seeding function, but it works ok. It supports 2^16 different seed values. Write something better if you need more seeds.

func (*Permutations) Seedf

func (s *Permutations) Seedf(seed float64)

Seed the noise functions. Only 65536 different seeds are supported. Use a float between 0 and 1 or an integer from 1 to 65536.

type Simplex2D

type Simplex2D struct {
	Permutations
}

func NewSimplex2D

func NewSimplex2D(seed float64) *Simplex2D

func (*Simplex2D) Noise

func (n *Simplex2D) Noise(x, y float64) float64

type Simplex3D

type Simplex3D struct {
	Permutations
}

Simplex3D is a 3D Simplex noise generator

func NewSimplex3D

func NewSimplex3D(seed float64) *Simplex3D

Seed the noise functions. Only 65536 different seeds are supported. Use a float between 0 and 1 or an integer from 1 to 65536.

func (*Simplex3D) Noise

func (d *Simplex3D) Noise(x, y, z float64) float64

Noise function returns a value in the range of -1 to 1.

Jump to

Keyboard shortcuts

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