opensimplex

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// Seed holds the seed value for the noise.
	Seed int64
}

Generator holds parameter values for OpenSimplex noise. It is an implementation of Generator interface.

func New

func New(seed int64) *Generator

New returns a seeded Perlin noise instance.

Example (Eval32_more_than_three_dimmentions)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const seed = 100

	p := opensimplex.New(seed)

	// It only supports up to three dimmentions.
	// OpenSimplex itself supports more but currently we strictly limit it to three.
	fmt.Printf("%0.0f", p.Eval32(0.0001, 0.0001, 0.0001, 0.0001))

}
Output:

0
Example (Eval32_one_dimmention)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const (
		seed       = 100
		smoothness = 100
	)

	p := opensimplex.New(seed)

	for x := float32(0); x < 3; x++ {
		fmt.Printf("%0.4f\n", p.Eval32(x/smoothness))
	}

}
Output:

0.0000
0.0102
0.0204
Example (Eval32_three_dimmentions)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const (
		seed       = 100
		smoothness = 100
	)

	p := opensimplex.New(seed)

	for z := float32(0); z < 2; z++ {
		for y := float32(0); y < 2; y++ {
			for x := float32(0); x < 2; x++ {
				fmt.Printf(
					"%0.4f\n",
					p.Eval32(x/smoothness, y/smoothness, z/smoothness),
				)
			}
		}
	}

}
Output:

0.0000
-0.0062
0.0062
0.0000
-0.0171
-0.0233
-0.0109
-0.0171
Example (Eval32_two_dimmentions)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const (
		seed       = 100
		smoothness = 100
	)

	p := opensimplex.New(seed)

	for y := float32(0); y < 2; y++ {
		for x := float32(0); x < 2; x++ {
			fmt.Printf(
				"%0.4f\n",
				p.Eval32(x/smoothness, y/smoothness),
			)
		}
	}

}
Output:

0.0000
0.0170
-0.0068
0.0102
Example (Eval64_more_than_three_dimmentions)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const seed = 100

	p := opensimplex.New(seed)

	// It only supports up to three dimmentions.
	// OpenSimplex itself supports more but currently we strictly limit it to three.
	fmt.Printf("%0.0f", p.Eval64(0.0001, 0.0001, 0.0001, 0.0001))

}
Output:

0
Example (Eval64_one_dimmention)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const (
		seed       = 100
		smoothness = 100
	)

	p := opensimplex.New(seed)

	for x := float64(0); x < 3; x++ {
		fmt.Printf(
			"%0.4f\n",
			p.Eval64(x/smoothness),
		)
	}

}
Output:

0.0000
0.0102
0.0204
Example (Eval64_three_dimmentions)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const (
		seed       = 100
		smoothness = 100
	)

	p := opensimplex.New(seed)

	for x := 0.; x < 2; x++ {
		for y := 0.; y < 2; y++ {
			for z := 0.; z < 2; z++ {
				fmt.Printf(
					"%0.4f\n",
					p.Eval64(x/smoothness, y/smoothness, z/smoothness),
				)
			}
		}
	}

}
Output:

0.0000
-0.0171
0.0062
-0.0109
-0.0062
-0.0233
0.0000
-0.0171
Example (Eval64_two_dimmentions)
package main

import (
	"fmt"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const (
		seed       = 100
		smoothness = 100
	)

	p := opensimplex.New(seed)

	for x := 0.; x < 2; x++ {
		for y := 0.; y < 2; y++ {
			for z := 0.; z < 2; z++ {
				fmt.Printf(
					"%0.4f\n",
					p.Eval64(x/smoothness, y/smoothness, z/smoothness),
				)
			}
		}
	}

}
Output:

0.0000
-0.0171
0.0062
-0.0109
-0.0062
-0.0233
0.0000
-0.0171

func (*Generator) Eval32

func (n *Generator) Eval32(dim ...float32) float32

Eval32 returns a float32 noise value for the given coordinates.

func (*Generator) Eval64

func (n *Generator) Eval64(dim ...float64) float64

Eval64 returns a float64 noise value for the given coordinates.

func (*Generator) SetEval32

func (n *Generator) SetEval32(f func(seed int64, dim ...float32) float32) error

SetEval32 is an implementation of noise.Generator interface. It will always return an error.

Example
package main

import (
	"fmt"
	"log"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const seed = 100

	p := opensimplex.New(seed)

	// User-defined functions cannot be assigned to OpenSimplex types. Use Custom type instead.
	err := p.SetEval32(func(seed int64, dim ...float32) float32 {
		return 0
	})

	if err == nil {
		log.Fatal("OpenSimplex type should return an error on SetEval32")
	}

	fmt.Println(err.Error())

}
Output:

float32 evaluation function is already set. You can not set custom function in OpenSimplex type

func (*Generator) SetEval64

func (n *Generator) SetEval64(f func(seed int64, dim ...float64) float64) error

SetEval64 is an implementation of noise.Generator interface. It will always return an error.

Example
package main

import (
	"fmt"
	"log"

	"github.com/KEINOS/go-noise/pkg/opensimplex"
)

func main() {
	const seed = 100

	p := opensimplex.New(seed)

	// User-defined functions cannot be assigned to OpenSimplex types. Use Custom type instead.
	err := p.SetEval64(func(seed int64, dim ...float64) float64 {
		return 0
	})

	if err == nil {
		log.Fatal("OpenSimplex type should return an error on SetEval32")
	}

	fmt.Println(err.Error())

}
Output:

float64 evaluation function is already set. You can not set custom function in OpenSimplex type

Jump to

Keyboard shortcuts

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