MCPcopy Index your code
hub / github.com/phaserjs/phaser / HexStringToColor

Function HexStringToColor

src/display/color/HexStringToColor.js:24–46  ·  view source on GitHub ↗
(hex, color)

Source from the content-addressed store, hash-verified

22 * @return {Phaser.Display.Color} A Color object populated by the values of the given string.
23 */
24var HexStringToColor = function (hex, color)
25{
26 if (!color) { color = new Color(); }
27
28 // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
29 hex = hex.replace(/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b)
30 {
31 return r + r + g + g + b + b;
32 });
33
34 var result = (/^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i).exec(hex);
35
36 if (result)
37 {
38 var r = parseInt(result[1], 16);
39 var g = parseInt(result[2], 16);
40 var b = parseInt(result[3], 16);
41
42 color.setTo(r, g, b);
43 }
44
45 return color;
46};
47
48module.exports = HexStringToColor;

Callers 2

ValueToColorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…