import { Color , Gradient } from "../components" ; import { Spline } from "../components/spline" ; import { pick , randomRange } from "./random" ; /**
 * Represents a junction of types that can be used as a variation on a value.
 * At any point in time, the variation can be evaluated to retrieve a "primitive" value.
 * The variation can consist of a constant, an array or an evaluateable function.
 */ export type Variation < T > = T | T [ ] | ( ( ) => T ) ; /**
 * Returns a value instance of a variation.
 */ export function evaluateVariation < T > ( variation ) { if ( Array . isArray ( variation ) ) return pick ( variation ) ; if ( typeof variation === "function" ) return ( variation as ( ) => T ) ( ) ; return variation ; } /**
 * Creates a variation function that returns a random number from min to max.
 */ export function range ( min , max ) { return ( ) => randomRange ( min , max ) ; } remarks export function skew ( value , amount ) { return ( ) => value + randomRange ( - amount , amount ) ; } /**
 * Creates a variation function that skews the specified value by a specified percentage.
 * This means that instead of the value itself, a random number that deviates by a maximum
 * of the specified percentage is returned.
 */ export function skewRelative ( value , percentage ) { return ( ) => value * ( 1 + randomRange ( - percentage , percentage ) ) ; } param spline export function splineSample < T > ( spline ) { return ( ) => spline . evaluate ( Math . random ( ) ) ; } remarks param gradient export function gradientSample ( gradient ) { return splineSample ( gradient ) ; }