Loaders
Loadersanimated

Pendulum

A weighted dot on a thread swinging back and forth from a pivot.

Installation

caveui components are copy-paste Jetpack Compose built entirely on Material 3 — there's no caveui dependency to add. Make sure Material 3 is on your classpath (it ships with the Compose BOM), then copy the Usage snippet below into your project.

kotlin
// build.gradle.kts (module)
dependencies {
    implementation(platform("androidx.compose:compose-bom:2025.06.00"))
    implementation("androidx.compose.material3:material3")
}

Usage

kotlin
val t = rememberInfiniteTransition(label = "pendulum")
val angle by t.animateFloat(
    initialValue = -16f,
    targetValue = 16f,
    animationSpec = infiniteRepeatable(
        tween(700, easing = FastOutSlowInEasing),
        RepeatMode.Reverse,
    ),
    label = "angle",
)
val thread = MaterialTheme.colorScheme.outline
val bob = MaterialTheme.colorScheme.primary
Canvas(Modifier.size(32.dp)) {
    rotate(angle, pivot = Offset(size.width / 2f, 0f)) {
        drawLine(
            color = thread,
            start = Offset(size.width / 2f, 0f),
            end = Offset(size.width / 2f, size.height - 5.dp.toPx()),
            strokeWidth = 1.5.dp.toPx(),
        )
        drawCircle(
            color = bob,
            radius = 5.dp.toPx(),
            center = Offset(size.width / 2f, size.height - 5.dp.toPx()),
        )
    }
}