/** * 随机生成颜色代码 * @returns #f716ed */ export function generateColorHEX(): string { const str = Math.floor(Math.random() * (256 * 256 * 256 - 1)).toString(16); return `#${str}`; } // /** * 生成随机的 RGB 颜色 * @returns rgb(24 144 255) / rgba(0,0,0,.85) */ export function generateColorRGBA(hasAlpha: boolean = false) { const red = Math.floor(Math.random() * 256); const green = Math.floor(Math.random() * 256); const blue = Math.floor(Math.random() * 256); if (hasAlpha) { const alpha = Math.floor(Math.random() * 100); return `rgb(${red}, ${green}, ${blue}, 0.${alpha})`; } return `rgb(${red}, ${green}, ${blue})`; }