Skip to content

Commit

Permalink
refactor: Optimize color fading algorithm in picker module
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixLuciano committed Jul 12, 2024
1 parent 0e6ac2a commit c2bbaa2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions public/picker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2bbaa2

Please sign in to comment.