Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/color.js
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
* @returns {number} | * @returns {number} | ||||
*/ | */ | ||||
function clampColorValue(value) | function clampColorValue(value) | ||||
{ | { | ||||
return Math.abs(1 - Math.abs(value - 1)); | return Math.abs(1 - Math.abs(value - 1)); | ||||
} | } | ||||
/** | /** | ||||
* @param {Number} efficiency - between 0 and 1 | |||||
* @returns {String} GUI color representing efficiency, 1 yields green, 0.5 yellow and 0 red. | |||||
*/ | |||||
function efficiencyToColor(efficiency) | |||||
{ | |||||
return hslToRgb(Math.min(1, Math.max(0, efficiency)) / 3, 1, 0.5).join(" "); | |||||
} | |||||
/** | |||||
* Convert color value from RGB to HSL space. | * Convert color value from RGB to HSL space. | ||||
* | * | ||||
* @see {@link https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion} | * @see {@link https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion} | ||||
* @param {number} r - red | * @param {number} r - red | ||||
* @param {number} g - green | * @param {number} g - green | ||||
* @param {number} b - blue | * @param {number} b - blue | ||||
* @returns {Array} | * @returns {Array} | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator