phaser/src/math/SinCosTableGenerator.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

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-01-26 06:19:27 +00:00
/**
* [description]
*
* @function Phaser.Math.SinCosTableGenerator
* @since 3.0.0
*
* @param {number} length - [description]
* @param {number} sinAmp - [description]
* @param {number} cosAmp - [description]
* @param {number} frequency - [description]
*
* @return {object} [description]
*/
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;