首页 > 其他分享 >随机颜色

随机颜色

时间:2022-10-12 17:26:17浏览次数:51  
标签:const colorMap random rgb 随机 颜色 256 Math

 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 };

 

标签:const,colorMap,random,rgb,随机,颜色,256,Math
From: https://www.cnblogs.com/lrtroot/p/16785240.html

相关文章