From 7040f0f644eb66fb6b240d7026b2904810a14a20 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Fri, 27 Jan 2023 14:32:01 +0800 Subject: [PATCH] feat: support rand by base color --- src/random.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/random.ts b/src/random.ts index 9620a78..6e0b0c4 100644 --- a/src/random.ts +++ b/src/random.ts @@ -1,9 +1,11 @@ import { Colord } from "./colord"; -export const random = (): Colord => { +export const random = (old?: Colord): Colord => { + const { r, g, b , a } = old?.toRgb() ?? { r: 255, g: 255, b: 255 , a: 1 }; return new Colord({ - r: Math.random() * 255, - g: Math.random() * 255, - b: Math.random() * 255, + r: r * 255, + g: g * 255, + b: b * 255, + a, }); };