fix:修改取色范围适应暗色模式

This commit is contained in:
zhongzm
2024-11-22 15:42:38 +08:00
parent c2a3d4b8a8
commit 886a1c8667

View File

@@ -13,12 +13,28 @@ export function generateColorHEX(): string {
* @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);
let red:number;
let green: number;
let blue:number;
red = Math.floor(Math.random() * 256)+100;//+100增加顏色亮度
green = Math.floor(Math.random() * 256)+100;
blue = Math.floor(Math.random() * 256)+100;
const brightChannel = Math.floor(Math.random() * 3);
switch (brightChannel) {
case 0:
red = Math.min(255, red + 50);
break;
case 1:
green = Math.min(255, green + 50);
break;
case 2:
blue = Math.min(255, blue + 50);
break;
}
if (hasAlpha) {
const alpha = Math.floor(Math.random() * 100);
const alpha = Math.floor(Math.random() * 100)+50;
return `rgb(${red}, ${green}, ${blue}, 0.${alpha})`;
}