From cc63b58413fdde99093ef38c476d861b15ed57e6 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Wed, 23 Sep 2026 15:19:17 +0000 Subject: [PATCH] cap the light accent luminance so overlay text stays readable --- .../com/subtracks/ui/theme/ArtworkTheme.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/subtracks/ui/theme/ArtworkTheme.kt b/app/src/main/kotlin/com/subtracks/ui/theme/ArtworkTheme.kt index 147a6475..c61acf91 100644 --- a/app/src/main/kotlin/com/subtracks/ui/theme/ArtworkTheme.kt +++ b/app/src/main/kotlin/com/subtracks/ui/theme/ArtworkTheme.kt @@ -33,6 +33,7 @@ import kotlin.random.Random private const val SEED_ART_SIZE_PX = 128 private const val GRADIENT_FADE_START = 1.3f / 2.0f private const val BLOB_ZONE = 0.62f +private const val ACCENT_MAX_LUMINANCE = 0.34f data class ArtworkColors( val scheme: ColorScheme, @@ -105,11 +106,28 @@ fun artworkColorsFromSeeds( scheme = scheme, gradientHigh = tone(hue, (s * 0.85f).coerceAtMost(0.65f), 0.30f), gradientLow = tone(hue, s * 0.45f, 0.04f), - accents = listOf(tone(hue, s, 0.72f), secondary), + accents = + listOf( + tone(hue, s, 0.72f).withMaxLuminance(ACCENT_MAX_LUMINANCE), + secondary.withMaxLuminance(ACCENT_MAX_LUMINANCE), + ), blobSeed = primarySeed, ) } +private fun Color.withMaxLuminance(max: Float): Color { + if (luminance() <= max) return this + val (h, s, initial) = toHsl() + var lightness = initial + var color = this + var guard = 0 + while (color.luminance() > max && guard++ < 30) { + lightness = (lightness - 0.02f).coerceAtLeast(0.05f) + color = Color.hsl(h, s, lightness) + } + return color +} + fun ArtworkColors.gradientColorAt(fraction: Float): Color { val t = fraction.coerceIn(0f, 1f) val base = lerp(gradientHigh, gradientLow, t)