From 886a1c8667779917c905bdf6f43162920d63a3b6 Mon Sep 17 00:00:00 2001 From: zhongzm Date: Fri, 22 Nov 2024 15:42:38 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9=E5=8F=96?= =?UTF-8?q?=E8=89=B2=E8=8C=83=E5=9B=B4=E9=80=82=E5=BA=94=E6=9A=97=E8=89=B2?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/generate-utils.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/utils/generate-utils.ts b/src/utils/generate-utils.ts index 57e009e5..863eeb28 100644 --- a/src/utils/generate-utils.ts +++ b/src/utils/generate-utils.ts @@ -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})`; }