Skip to content

noise #

vsl.noise

vsl.noise.Generator holds a permutation table for Perlin and simplex noise. Create a generator, seed V's rand module first when repeatable output is needed, then call randomize() to shuffle its table.

Method Dimensions
perlin2d(x, y), perlin3d(x, y, z) Classic gradient Perlin noise in 2D and 3D.
simplex_1d(x) through simplex_4d(x, ...) Simplex noise in one through four dimensions.

Values are scalar f64s. Scale coordinates to control frequency; combine several frequencies in an application when building fractal noise.

import rand
import vsl.noise

rand.seed([u32(3155200429), u32(3208395956)])
mut generator := noise.Generator.new()
generator.randomize()
sample := generator.simplex_2d(0.03, 0.06)
println(sample)

Examples: 2D simplex heatmap, fractal noise, and quaternion noise. See noise.v and simplex.v for the exported methods.

fn Generator.new #

fn Generator.new() Generator

new is a function that return a new Generator struct

struct Generator #

struct Generator {
mut:
	perm []int = rand.shuffle_clone(permutations) or { panic(err) }
}

Generator is a struct holding the permutation table used in perlin and simplex noise

fn (Generator) randomize #

fn (mut gen Generator) randomize()

randomize is a function that shuffle the permutation set inside the Generator struct

fn (Generator) perlin_2d #

fn (gen Generator) perlin_2d(x f64, y f64) f64

perlin_2d is a function that return a single value of perlin gen for a given 2d position

fn (Generator) perlin2d #

fn (gen Generator) perlin2d(x f64, y f64) f64

perlin2d is kept as a compatibility alias for perlin_2d.

fn (Generator) perlin_3d #

fn (gen Generator) perlin_3d(x f64, y f64, z f64) f64

perlin_3d is a function that return a single value of perlin gen for a given 3d position

fn (Generator) perlin3d #

fn (gen Generator) perlin3d(x f64, y f64, z f64) f64

perlin3d is kept as a compatibility alias for perlin_3d.

fn (Generator) simplex_1d #

fn (gen Generator) simplex_1d(x f64) f64

simplex_1d returns a simplex noise value for a given x position

fn (Generator) simplex_2d #

fn (gen Generator) simplex_2d(x f64, y f64) f64

simplex_2d returns a simplex noise value for a given x, y position

fn (Generator) simplex_3d #

fn (gen Generator) simplex_3d(x f64, y f64, z f64) f64

simplex_3d returns a simplex noise value for a given x, y, z position

fn (Generator) simplex_4d #

fn (gen Generator) simplex_4d(x f64, y f64, z f64, w f64) f64

simplex_4d returns a simplex noise value for a given x, y, z, w position