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