随机颜色

 1 /**
 2  * 随机颜色
 3  * @param: colorMap {颜色: true} 生成不在该数据内的color
 4  */
 5 export const getRgbColorRandom = (colorMap = {}, transparency = 0.1) => {
 6   const r = Math.floor(Math.random() * 256);
 7   const g = Math.floor(Math.random() * 256);
 8   const b = Math.floor(Math.random() * 256);
 9   if (r === g && g === b) return getRgbColorRandom(colorMap);
10   const rgb = `rgb(${r},${g},${b},${transparency})`;
11   if (colorMap[rgb]) return getRgbColorRandom(colorMap);
12   return rgb;
13 };

 

posted @ 2022-10-12 17:13  lrt-web  阅读(268)  评论(0)    收藏  举报