Random utilities

Meowshapes provides several utility functions for generating random values, including noise and Fractal Brownian Motion (fbm). These functions are useful for creating procedural textures, terrains, and other effects.


Noise

Use the noise(...) function to generate Simplex noise values.

import { noise } from "meowshapes";

const dim1 = noise(1);
const dim2 = noise([1, 2]);
const dim3 = noise([1, 2, 3]);

Seeding

You can seed the noise function to get consistent results across calls:

import { noise } from "meowshapes";

const seededNoise = noise([1, 2, 3], "some-seed");

Example

camera.position.set(0, 0, 1);
camera.lookAt(0, 0, 0);

zoom(100);

graph((x) => noise(x));

Fractal Brownian Motion (fbm)

Use the fbm(...) function to generate Fractal Brownian Motion values, which combine multiple octaves of noise for more complex patterns.

import { fbm } from "meowshapes";

const dim1 = fbm(1);
const dim2 = fbm([1, 2]);
const dim3 = fbm([1, 2, 3]);

Config

You can customize the fbm function with additional parameters:

import { fbm } from "meowshapes";

const value = fbm([1, 2, 3], {
	// Number of noise layers:
	octaves: 5,
	// Frequency multiplier between octaves:
	lacunarity: 2.0,
	// Amplitude multiplier between octaves:
	gain: 0.5,
	// Seed for noise generation:
	seed: "some-seed"
});

Example

camera.position.set(0, 0, 1);
camera.lookAt(0, 0, 0);

zoom(100);

graph((x) => fbm(x, { octaves: 6 }));