feat: 黄金指标项随机颜色
This commit is contained in:
26
src/utils/generate-utils.ts
Normal file
26
src/utils/generate-utils.ts
Normal 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})`;
|
||||
}
|
||||
Reference in New Issue
Block a user