Skip to content

Commit

Permalink
fix saturation 0 bug with math max
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoLuglio committed Oct 1, 2024
1 parent 07dc3b2 commit 63cfb0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/lib/generator/syntaxColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomInteger } from '@/lib/utils/math'
import { adjustCommentColor, ensureReadability } from './colorUtils'
import { SyntaxColors } from '@/lib/types/colors'
import Color from 'color'
import { Exo_2 } from 'next/font/google'

export function generateSyntaxColors(
backgroundColor: string,
Expand All @@ -23,7 +24,10 @@ export function generateSyntaxColors(
highContrast: boolean = true
) => {
const hue = (schemeHues[hueIndex % schemeHues.length] + hueShift) % 360
const saturation = Math.min(100, syntaxSaturation * saturationMultiplier)
const saturation = Math.max(
2,
Math.min(100, syntaxSaturation * saturationMultiplier)
)
const lightness = Math.min(
100,
Math.max(
Expand Down Expand Up @@ -281,11 +285,10 @@ export function updateSyntaxColorsWithSaturation(
saturationMultiplier: number
) => {
const hsl = Color(color).hsl()
let newSaturation = Math.min(
100,
newSyntaxSaturation * saturationMultiplier
let newSaturation = Math.max(
2,
Math.min(100, newSyntaxSaturation * saturationMultiplier)
)
if (newSaturation < 2) newSaturation = 2
return Color.hsl(hsl.hue(), newSaturation, hsl.lightness()).hex()
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib/generator/uiColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function generateThemeColors(

hue = (hue + randomHueShift + 360) % 360
saturation = Math.max(
0,
2,
Math.min(100, saturation + randomSaturationShift)
)
lightness = Math.max(0, Math.min(100, lightness + randomLightnessShift))
Expand Down Expand Up @@ -203,8 +203,10 @@ export function updateThemeColorsWithSaturation(
saturationMultiplier: number
) => {
const hsl = Color(color).hsl()
let newSaturation = Math.min(100, newUiSaturation * saturationMultiplier)
if (newSaturation < 2) newSaturation = 2
let newSaturation = Math.max(
2,
Math.min(100, newUiSaturation * saturationMultiplier)
)
return Color.hsl(hsl.hue(), newSaturation, hsl.lightness()).hex()
}

Expand Down

0 comments on commit 63cfb0c

Please sign in to comment.