perlin

package module
v0.0.0-...-e4c4679 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2014 License: BSD-2-Clause Imports: 2 Imported by: 1

README

perlin Build Status Coverage Status GoDoc

Yet another Go library implementing Perlin noise.

Features:

  • You can have multiple independent generators
  • Each generator can be re-parametrised, re-seeded and reused
  • Noise for 1, 2 and 3 dimensions
  • Full test coverage, includes benchmarks

The library is a direct rip-off of aquilax/go-perlin, which in turn has been based on this, which was ultimately based on the work of Ken Perlin. I'm licensing it under my usual two clause BSD license, if anybody has a problem with that please do tell.

Showcase

Using the included perlin command:

$ cd cmd/perlin
$ go build
$ ./perlin
Usage: ./perlin [options] path
  -a=2: alpha factor
  -b=2: beta factor
  -c=false: smooth (continuous) gradient
  -h=256: image height
  -n=1: octave factor
  -r=1417875091: random seed
  -s=1: scaling factor
  -w=320: image width
$ ./perlin -c -a 1.25 -b 1.88 -n 10 -r 1 example.png

Example output

Usage notes

All functions return values in the range of <-1.0, 1.0>. Once seeded the generator is fully deterministic. Please see docs for more information.

Benchmarks (linux x64, Intel i7-2620M @ 2.70GHz):

PASS
BenchmarkNoise1D        100000000               14.9 ns/op
BenchmarkNoise2D        100000000               27.0 ns/op
BenchmarkNoise3D        50000000                46.6 ns/op
ok      github.com/drbig/perlin 6.631s

Licensing

Standard two-clause BSD license, see LICENSE.txt for details.

Copyright (c) 2014 Piotr S. Staszewski

Documentation

Overview

Package perlin implements reusable Perlin noise generators.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	Alpha float64 // Alpha is the weight factor used during summing
	Beta  float64 // Beta is the harmonic scaling/spacing factor
	N     int     // N is the number of octaves/samples
	Seed  int64   // Seed is the number used to seed the RNG
	// contains filtered or unexported fields
}

Generator holds Perlin noise parameters and random seed.

func NewGenerator

func NewGenerator(alpha, beta float64, n int, seed int64) *Generator

NewGenerator returns seeded Generator for given parameters.

func (*Generator) Noise1D

func (g *Generator) Noise1D(x float64) float64

Noise1D calculates Perlin noise at point x.

func (*Generator) Noise2D

func (g *Generator) Noise2D(x, y float64) float64

Noise2D calculates Perlin noise at point x,y.

Example
g1 := NewGenerator(2, 2, 1, 41)
g2 := NewGenerator(2, 2, 1, 4231)
fmt.Printf("g1 noise at 0.1, 0.2 = %f\n", g1.Noise2D(0.1, 0.2))
fmt.Printf("g2 noise at 0.1, 0.2 = %f\n", g2.Noise2D(0.1, 0.2))
Output:

g1 noise at 0.1, 0.2 = -0.125053
g2 noise at 0.1, 0.2 = 0.182675

func (*Generator) Noise3D

func (g *Generator) Noise3D(x, y, z float64) float64

Noise3D calculates Perlin noise at point x,y,z. For small values of z this will be equivalent to calling Noise2D(x, y).

func (*Generator) Reset

func (g *Generator) Reset(seed int64)

Reset re-seeds an existing Generator. Note that you can change other parameters before calling this, effectively completely re-parametrising the Generator.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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