was.js – Diff between revs 25 and 27

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