1 | ;
|
2 |
|
3 | /**
|
4 | * Oscillate between -1 and 1 given a value and a period. This is basically a simplification on using Math.sin().
|
5 | * @alias Splat.math.oscillate
|
6 | * @param {number} current The current value of the number you want to oscillate.
|
7 | * @param {number} period The period, or how often the number oscillates. The return value will oscillate between -1 and 1, depending on how close current is to a multiple of period.
|
8 | * @returns {number} A number between -1 and 1.
|
9 | * @example
|
10 | Splat.math.oscillate(0, 100); // returns 0
|
11 | Splat.math.oscillate(100, 100); // returns 0-ish
|
12 | Splat.math.oscillate(50, 100); // returns 1
|
13 | Splat.math.oscillate(150, 100); // returns -1
|
14 | Splat.math.oscillate(200, 100); // returns 0-ish
|
15 | */
|
16 | function oscillate(current, period) {
|
17 | return Math.sin(current / period * Math.PI);
|
18 | }
|
19 |
|
20 | /**
|
21 | * @namespace Splat.math
|
22 | */
|
23 | module.exports = {
|
24 | oscillate: oscillate,
|
25 | /**
|
26 | * A seedable pseudo-random number generator. Currently a Mersenne Twister PRNG.
|
27 | * @constructor
|
28 | * @alias Splat.math.Random
|
29 | * @param {number} [seed] The seed for the PRNG.
|
30 | * @see [mersenne-twister package at github]{@link https://github.com/boo1ean/mersenne-twister}
|
31 | * @example
|
32 | var rand = new Splat.math.Random(123);
|
33 | var val = rand.random();
|
34 | */
|
35 | Random: require("mersenne-twister")
|
36 | };
|