Skip to content

Commit b51b0a1

Browse files
committed
Add Math.Angle.Random() and Math.Angle.RandomDegrees()
1 parent f57c0a3 commit b51b0a1

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/math/angle/Random.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var FloatBetween = require('../FloatBetween');
2+
var CONST = require('../const');
3+
4+
/**
5+
* Returns a random angle in the range [0, 2pi].
6+
*
7+
* @function Phaser.Math.Angle.Random
8+
* @since 3.23.0
9+
*
10+
* @return {number} The angle, in radians.
11+
*/
12+
var Random = function ()
13+
{
14+
return FloatBetween(0, CONST.PI2);
15+
};
16+
17+
module.exports = Random;

src/math/angle/RandomDegrees.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var FloatBetween = require('../FloatBetween');
2+
3+
/**
4+
* Returns a random angle in the range [0, 360].
5+
*
6+
* @function Phaser.Math.Angle.RandomDegrees
7+
* @since 3.23.0
8+
*
9+
* @return {number} The angle, in degrees.
10+
*/
11+
var RandomDegrees = function ()
12+
{
13+
return FloatBetween(0, 360);
14+
};
15+
16+
module.exports = RandomDegrees;

src/math/angle/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module.exports = {
1616
BetweenY: require('./BetweenY'),
1717
CounterClockwise: require('./CounterClockwise'),
1818
Normalize: require('./Normalize'),
19+
Random: require('./Random'),
20+
RandomDegrees: require('./RandomDegrees'),
1921
Reverse: require('./Reverse'),
2022
RotateTo: require('./RotateTo'),
2123
ShortestBetween: require('./ShortestBetween'),

0 commit comments

Comments
 (0)