phaser/src/math/FromPercent.js

29 lines
798 B
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}
*/
2017-10-17 20:31:28 +00:00
var Clamp = require('./Clamp');
/**
* Return a value based on the range between `min` and `max` and the percentage given.
*
* @function Phaser.Math.FromPercent
* @since 3.0.0
*
* @param {float} percent - A value between 0 and 1 representing the percentage.
* @param {number} min - The minimum value.
* @param {number} [max] - The maximum value.
2017-10-17 20:31:28 +00:00
*
* @return {number} The value that is `percent` percent between `min` and `max`.
2017-10-17 20:31:28 +00:00
*/
var FromPercent = function (percent, min, max)
{
percent = Clamp(percent, 0, 1);
return (max - min) * percent;
};
module.exports = FromPercent;