was.js – Blame information for rev 34

Subversion Repositories:
Rev:
Rev Author Line No. Line
7 office 1 /*************************************************************************/
2 /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */
3 /*************************************************************************/
8 office 4 function wasHexToRGB(hex) {
7 office 5 var shortRegEx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
6 hex = hex.replace(
8 office 7 shortRegEx,
7 office 8 function(m, r, g, b) {
9 return r + r + g + g + b + b;
10 }
11 );
8 office 12  
7 office 13 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
14 return result ? {
15 r: parseInt(result[1], 16),
16 g: parseInt(result[2], 16),
17 b: parseInt(result[3], 16)
18 } : null;
8 office 19 }
20  
21 /*************************************************************************/
22 /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */
23 /*************************************************************************/
24 function wasRGBToHex(r, g, b) {
25 return "#" + (
26 (1 << 24) +
27 (r << 16) +
28 (g << 8) +
29 b
30 ).toString(16).slice(1);
31 }
25 office 32  
33 /*************************************************************************/
34 /* Node.JS package export. */
35 /*************************************************************************/
34 office 36 if(typeof variable !== 'undefined') {
37 module.exports.physics = {
38 HexToRGB: wasHexToRGB,
39 RGBToHex: wasRGBToHex
40 };
41 }