From c2bbaa2e92e239676b4a33b38981a1e27b8adc0c Mon Sep 17 00:00:00 2001 From: FelixLuciano Date: Fri, 12 Jul 2024 17:18:49 -0300 Subject: [PATCH] refactor: Optimize color fading algorithm in picker module --- public/picker.mjs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/public/picker.mjs b/public/picker.mjs index 55bab66..11bff4f 100644 --- a/public/picker.mjs +++ b/public/picker.mjs @@ -253,13 +253,20 @@ export function picker() { const interpolateLight = interpolate(this.lightFade, this.color) for (let i = this.darkAmount; i > 0; i--) { - fades.push(interpolateDark(i / this.darkAmount)) + const fade = interpolateDark(i / this.darkAmount) + + if (fade.hex !== fades[fades.length - 1]?.hex) + fades.push(fade) } - fades.push(this.color) + if (this.color.hex !== fades[fades.length - 1]?.hex) + fades.push(this.color) for (let i = this.lightAmount; i > 0; i--) { - fades.push(interpolateLight((i - 1) / this.lightAmount)) + const fade = interpolateLight((i - 1) / (this.lightAmount)) + + if (fade.hex !== fades[fades.length - 1]?.hex) + fades.push(fade) } return fades