UNPKG

agentscape

Version:

Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing

35 lines (29 loc) 1.08 kB
import { createNoise2D } from 'simplex-noise' import RandomGenerator from './RandomGenerator' export default class NoiseGenerator { /** * Generates noise with a uniform distribution. */ public static uniform(rng: RandomGenerator, min: number = 0, max: number = 1): number { return rng.uniformFloat(0, 1) * (max - min) + min } /** * Generates noise with a Gaussian distribution. */ public static gaussian(rng: RandomGenerator, mean: number = 0, stdDev: number = 1): number { const c = rng.normalFloat(mean, stdDev) return c * stdDev + mean } /** * Generates completely random values with no correlation between successive outputs. */ public static white(rng: RandomGenerator, stdDev: number = 1): number { return (rng.uniformFloat(0, 1) * 2 - 1) * stdDev } /** * Generates 2D Simplex noise with output [-1, 1]. */ public static simplex(rng: RandomGenerator): (x: number, y: number) => number { return createNoise2D(() => rng.uniformFloat(0, 1)) } }