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}
|
|
|
|
*/
|
|
|
|
|
2017-10-06 03:52:41 +00:00
|
|
|
/**
|
2018-05-23 09:46:16 +00:00
|
|
|
* Compute a random unit vector.
|
|
|
|
*
|
|
|
|
* Computes random values for the given vector between -1 and 1 that can be used to represent a direction.
|
|
|
|
*
|
|
|
|
* Optionally accepts a scale value to scale the resulting vector by.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Math.RandomXY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @param {Phaser.Math.Vector2} vector - The Vector to compute random values for.
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} [scale=1] - The scale of the random values.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @return {Phaser.Math.Vector2} The given Vector.
|
2017-10-06 03:52:41 +00:00
|
|
|
*/
|
2017-09-18 20:48:26 +00:00
|
|
|
var RandomXY = function (vector, scale)
|
|
|
|
{
|
|
|
|
if (scale === undefined) { scale = 1; }
|
|
|
|
|
|
|
|
var r = Math.random() * 2 * Math.PI;
|
|
|
|
|
|
|
|
vector.x = Math.cos(r) * scale;
|
|
|
|
vector.y = Math.sin(r) * scale;
|
|
|
|
|
|
|
|
return vector;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = RandomXY;
|