arcade-physics
Version:
Use Arcade Physics without Phaser.
36 lines • 1.37 kB
JavaScript
;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Point_1 = __importDefault(require("../point/Point"));
/**
* Returns a uniformly distributed random point from anywhere within the given Ellipse.
*
* @function Phaser.Geom.Ellipse.Random
* @since 3.0.0
*
* @generic {Phaser.Geom.Point} O - [out,$return]
*
* @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get a random point from.
* @param {(Phaser.Geom.Point|object)} [out] - A Point or point-like object to set the random `x` and `y` values in.
*
* @return {(Phaser.Geom.Point|object)} A Point object with the random values set in the `x` and `y` properties.
*/
const Random = (ellipse, out) => {
if (out === undefined) {
out = new Point_1.default();
}
const p = Math.random() * Math.PI * 2;
const s = Math.sqrt(Math.random());
out.x = ellipse.x + (s * Math.cos(p) * ellipse.width) / 2;
out.y = ellipse.y + (s * Math.sin(p) * ellipse.height) / 2;
return out;
};
exports.default = Random;
//# sourceMappingURL=Random.js.map