0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

added Common.colorToNumber and Common.log

This commit is contained in:
liabru 2014-03-19 12:51:01 +00:00
parent 56768a4c9d
commit c8ebf8b9f4

View file

@ -223,4 +223,45 @@ var Common = {};
return min + Math.random() * (max - min);
};
/**
* Converts a CSS hex colour string into an integer
* @method colorToNumber
* @param {string} colorString
* @return {number} An integer representing the CSS hex string
*/
Common.colorToNumber = function(colorString) {
colorString = colorString.replace('#','');
if (colorString.length == 3) {
colorString = colorString.charAt(0) + colorString.charAt(0)
+ colorString.charAt(1) + colorString.charAt(1)
+ colorString.charAt(2) + colorString.charAt(2);
}
return parseInt(colorString, 16);
};
/**
* A wrapper for console.log, for providing errors and warnings
* @method log
* @param {string} message
* @param {string} type
*/
Common.log = function(message, type) {
if (!console || !console.log)
return;
var style;
switch (type) {
case 'warn':
style = 'color: coral';
break;
case 'error':
style = 'color: red';
}
console.log('%c [Matter] ' + type + ': ' + message, style);
};
})();