标签:offset numa substr int str orb off 判断 fse
RBG转灰度
//rgba(grey,grey,grey,1) function rgb2Grey(r,g,b) { var grey=Math.round((r*299 + g*587 + b*114 + 500) / 1000) return grey }
判断两种颜色相似程度
//rbg function isSimilarColorRBG(r1, g1, b1, r2, g2, b2, offset) { if (Math.sqrt((r1 - r2) * (r1 - r2) + (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2)) < offset) { return true; } else { return false; } } //hex function isSimilarColorHEX(sHexColorA, sHexColorB, nOffset) { this.offsetNum = Math.abs(nOffset); this.offsetNum > 255 ? this.offsetNum = this.offsetNum - 256 : ""; var arrNumA = [parseInt(sHexColorA.substring(0, 2), 16), parseInt(sHexColorA.substring(2, 4), 16), parseInt(sHexColorA.substring(4, 6), 16) ]; var arrNumB = [parseInt(sHexColorB.substring(0, 2), 16), parseInt(sHexColorB.substring(2, 4), 16), parseInt(sHexColorB.substring(4, 6), 16) ]; for (var i = 0; i < arrNumA.length; i++) { if (Math.abs(arrNumA[i] - arrNumB[i]) > this.offsetNum) { return false;//不相似 }; } return true;//相似 }
RGB转HEX
//rgbToHex("rbg(r,g,b)") function rgbToHex(rgb) { var color = rgb.toString().match(/\d+/g); var hex = "#"; for (var i = 0; i < 3; i++) { hex += ("0" + Number(color[i]).toString(16)).slice(-2); } return hex; }
标签:offset numa substr int str orb off 判断 fse
原文地址:http://www.cnblogs.com/luoeeyang/p/7089282.html