mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
The HSVToRGB
function can now take an optional out
argument, which is either a HSVColorObject
or a Color
object, and the results will be set into that object instead of creating a new one.
This commit is contained in:
parent
664d5efc7b
commit
fccd58b097
1 changed files with 44 additions and 27 deletions
|
@ -15,13 +15,14 @@ var GetColor = require('./GetColor');
|
|||
* @function Phaser.Display.Color.HSVToRGB
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} h - The hue, in the range 0 - 1.
|
||||
* @param {number} s - The saturation, in the range 0 - 1.
|
||||
* @param {number} v - The value, in the range 0 - 1.
|
||||
* @param {number} h - The hue, in the range 0 - 1. This is the base color.
|
||||
* @param {number} s - The saturation, in the range 0 - 1. This controls how much of the hue will be in the final color, where 1 is fully saturated and 0 will give you white.
|
||||
* @param {number} v - The value, in the range 0 - 1. This controls how dark the color is. Where 1 is as bright as possible and 0 is black.
|
||||
* @param {(ColorObject|Phaser.Display.Color)} [out] - A Color object to store the results in. If not given a new ColorObject will be created.
|
||||
*
|
||||
* @return {ColorObject} An object with the red, green and blue values set in the r, g and b properties.
|
||||
* @return {(ColorObject|Phaser.Display.Color)} An object with the red, green and blue values set in the r, g and b properties.
|
||||
*/
|
||||
var HSVToRGB = function (h, s, v)
|
||||
var HSVToRGB = function (h, s, v, out)
|
||||
{
|
||||
if (s === undefined) { s = 1; }
|
||||
if (v === undefined) { v = 1; }
|
||||
|
@ -35,44 +36,60 @@ var HSVToRGB = function (h, s, v)
|
|||
|
||||
v = Math.floor(v *= 255);
|
||||
|
||||
var output = { r: v, g: v, b: v, color: 0 };
|
||||
var r = v;
|
||||
var g = v;
|
||||
var b = v;
|
||||
|
||||
var r = i % 6;
|
||||
var c = i % 6;
|
||||
|
||||
if (r === 0)
|
||||
if (c === 0)
|
||||
{
|
||||
output.g = t;
|
||||
output.b = p;
|
||||
g = t;
|
||||
b = p;
|
||||
}
|
||||
else if (r === 1)
|
||||
else if (c === 1)
|
||||
{
|
||||
output.r = q;
|
||||
output.b = p;
|
||||
r = q;
|
||||
b = p;
|
||||
}
|
||||
else if (r === 2)
|
||||
else if (c === 2)
|
||||
{
|
||||
output.r = p;
|
||||
output.b = t;
|
||||
r = p;
|
||||
b = t;
|
||||
}
|
||||
else if (r === 3)
|
||||
else if (c === 3)
|
||||
{
|
||||
output.r = p;
|
||||
output.g = q;
|
||||
r = p;
|
||||
g = q;
|
||||
}
|
||||
else if (r === 4)
|
||||
else if (c === 4)
|
||||
{
|
||||
output.r = t;
|
||||
output.g = p;
|
||||
r = t;
|
||||
g = p;
|
||||
}
|
||||
else if (r === 5)
|
||||
else if (c === 5)
|
||||
{
|
||||
output.g = p;
|
||||
output.b = q;
|
||||
g = p;
|
||||
b = q;
|
||||
}
|
||||
|
||||
output.color = GetColor(output.r, output.g, output.b);
|
||||
if (!out)
|
||||
{
|
||||
return { r: r, g: g, b: b, color: GetColor(r, g, b) };
|
||||
}
|
||||
else if (out.setTo)
|
||||
{
|
||||
return out.setTo(r, g, b, out.alpha, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
out.r = r;
|
||||
out.g = g;
|
||||
out.b = b;
|
||||
out.color = GetColor(r, g, b);
|
||||
|
||||
return output;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = HSVToRGB;
|
||||
|
|
Loading…
Reference in a new issue