feat: 黄金指标项随机颜色

This commit is contained in:
TsMask
2024-02-06 12:00:48 +08:00
parent 7dd851a2d7
commit 43afd76610
2 changed files with 48 additions and 55 deletions

View File

@@ -0,0 +1,26 @@
/**
* 随机生成颜色代码
* @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})`;
}