angled-gradient-modifier

Installation
SKILL.md

Angled gradient background

Brush.linearGradient takes two points, not an angle. So "a gradient at 30°" is really the question where do the two endpoints go so the ramp completes exactly across the box at 30°, and the answer depends on the box's aspect ratio — which is why the same brush cannot be built once at composition time. The whole thing lives inside a draw modifier, where the size is known.

// adapted (guard clauses trimmed; see Traps for the ones that were removed)
fun Modifier.angledGradientBackground(colors: List<Color>, degrees: Float) =
    this.then(
        if (colors.size < 2) Modifier else Modifier.drawBehind {
            val (x, y) = size
            val gamma = atan2(y, x)                 // angle of the box's own corner
            if (gamma == 0f || gamma == (PI / 2).toFloat()) return@drawBehind

            val degreesNormalised = (degrees % 360).let { if (it < 0) it + 360 else it }
            val alpha = (degreesNormalised * PI / 180).toFloat()
Installs
2
GitHub Stars
35
First Seen
6 days ago
angled-gradient-modifier — maxrave-dev/kotlin-footguns