improved color key generation algorithm

This commit is contained in:
Eric Rowell
2013-04-11 23:09:41 -07:00
parent cbb9e2c289
commit 60c9ef5bcd

View File

@@ -283,20 +283,12 @@
_rgbToHex: function(r, g, b) { _rgbToHex: function(r, g, b) {
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}, },
_hexToRgb: function(hex) {
var bigint = parseInt(hex, 16);
return {
r: (bigint >> 16) & 255,
g: (bigint >> 8) & 255,
b: bigint & 255
};
},
_getRandomColorKey: function() { _getRandomColorKey: function() {
var r = (Math.random() * 255) | 0, var randColor = (Math.random() * 0xFFFFFF << 0).toString(16);
g = (Math.random() * 255) | 0, while (randColor.length < 6) {
b = (Math.random() * 255) | 0; randColor = '0' + randColor;
}
return this._rgbToHex(r, g, b); return randColor;
}, },
// o1 takes precedence over o2 // o1 takes precedence over o2
_merge: function(o1, o2) { _merge: function(o1, o2) {