fix:修改取色范围适应暗色模式
This commit is contained in:
@@ -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})`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user