2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-03-21 13:15:25 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} SinCosTable
|
|
|
|
*
|
2018-05-31 15:29:29 +00:00
|
|
|
* @property {number} sin - The sine value.
|
|
|
|
* @property {number} cos - The cosine value.
|
|
|
|
* @property {number} length - The length.
|
2018-03-21 13:15:25 +00:00
|
|
|
*/
|
2016-12-07 17:16:59 +00:00
|
|
|
|
2018-01-26 06:19:27 +00:00
|
|
|
/**
|
2018-05-31 15:29:29 +00:00
|
|
|
* Generate a series of sine and cosine values.
|
2018-01-26 06:19:27 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Math.SinCosTableGenerator
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-31 15:29:29 +00:00
|
|
|
* @param {number} length - The number of values to generate.
|
|
|
|
* @param {number} [sinAmp=1] - The sine value amplitude.
|
|
|
|
* @param {number} [cosAmp=1] - The cosine value amplitude.
|
|
|
|
* @param {number} [frequency=1] - The frequency of the values.
|
2018-01-26 06:19:27 +00:00
|
|
|
*
|
2018-05-31 15:29:29 +00:00
|
|
|
* @return {SinCosTable} The generated values.
|
2018-01-26 06:19:27 +00:00
|
|
|
*/
|
2016-12-07 17:16:59 +00:00
|
|
|
var SinCosTableGenerator = function (length, sinAmp, cosAmp, frequency)
|
|
|
|
{
|
|
|
|
if (sinAmp === undefined) { sinAmp = 1; }
|
|
|
|
if (cosAmp === undefined) { cosAmp = 1; }
|
|
|
|
if (frequency === undefined) { frequency = 1; }
|
|
|
|
|
|
|
|
frequency *= Math.PI / length;
|
|
|
|
|
|
|
|
var cos = [];
|
|
|
|
var sin = [];
|
|
|
|
|
|
|
|
for (var c = 0; c < length; c++)
|
|
|
|
{
|
|
|
|
cosAmp -= sinAmp * frequency;
|
|
|
|
sinAmp += cosAmp * frequency;
|
|
|
|
|
|
|
|
cos[c] = cosAmp;
|
|
|
|
sin[c] = sinAmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
sin: sin,
|
|
|
|
cos: cos,
|
|
|
|
length: length
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SinCosTableGenerator;
|