phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.
29 lines (24 loc) • 826 B
JavaScript
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2026 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Clamp = require('./Clamp');
/**
* Returns a value based on the range between `min` and `max` and the percentage given.
*
* @function Phaser.Math.FromPercent
* @since 3.0.0
*
* @param {number} percent - A value representing the percentage, between 0 and 1. Values outside this range are clamped to it.
* @param {number} min - The minimum value.
* @param {number} [max] - The maximum value.
*
* @return {number} The value that is `percent` percent between `min` and `max`.
*/
var FromPercent = function (percent, min, max)
{
percent = Clamp(percent, 0, 1);
return (max - min) * percent + min;
};
module.exports = FromPercent;