(hex, color)
| 22 | * @return {Phaser.Display.Color} A Color object populated by the values of the given string. |
| 23 | */ |
| 24 | var 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 | |
| 48 | module.exports = HexStringToColor; |
no outgoing calls
no test coverage detected
searching dependent graphs…