Let’s say I have two colors, if I have a hexadecimal color value
var str1 = “#aabbcc”;
/ var reg1 = {1, 2}) (\ w/g;
var rs1 = str1.match(reg1);
var r1 = parseInt(“0x”+rs1[0]);
var g1 = parseInt(“0x”+rs1[1]);
var b1 = parseInt(“0x”+rs1[2]);
var str2= “#aabbcc”;
/ var reg2 = {1, 2}) (\ w/g;
var rs2 = str2.match(reg2);
var r2 = parseInt(“0x”+rs2[0]);
var g2 = parseInt(“0x”+rs2[1]);
var b2 = parseInt(“0x”+rs2[2]);
Then for the two colors, you can use distance Math.sqrt((R1-R2)*(R1-R2)+(G1-G2)*(G1-G2)+(B1-B2)*(b1-B2)) for comparison, and close distances are similar.