Skip to content

Instantly share code, notes, and snippets.

@ibeeger
Created June 12, 2018 03:32
Show Gist options
  • Save ibeeger/e2b821d7cc7e621389d2ae109d7d2c38 to your computer and use it in GitHub Desktop.
Save ibeeger/e2b821d7cc7e621389d2ae109d7d2c38 to your computer and use it in GitHub Desktop.
判断两色素颜色的相似度
var Distance = 150; //设置阀值 结果和该值比较,如果小于它就代表相似
//color1 = {r:xxx,b:xxx,g:xxx};
function Compared(color1,color2){
let _liked = false;
let _r = color1.r-color2.r;
let _g = color1.g-color2.g;
let _b = color1.b-color2.b;
if(Math.sqrt(Math.pow(_r,2)+Math.pow(_g,2)+Math.pow(_g,2))<Distance){
_liked = true;
}
return _liked;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment