Cards
Cardsanimated

Music Visualizer

Full-width visualizer card rendering many animated frequency bars on canvas.

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
@Composable
fun MusicVisualizer() {
  val t = rememberInfiniteTransition(label = "vis")
  val phase by t.animateFloat(
    initialValue = 0f,
    targetValue = (2 * PI).toFloat(),
    animationSpec = infiniteRepeatable(
      tween(1400, easing = LinearEasing),
    ),
    label = "phase",
  )
  Card(
    shape = RoundedCornerShape(20.dp),
    modifier = Modifier.fillMaxWidth(),
  ) {
    Canvas(
      modifier = Modifier
        .fillMaxWidth()
        .height(96.dp)
        .padding(16.dp),
    ) {
      val n = 24
      val gap = size.width / n
      for (i in 0 until n) {
        val h = (sin(phase + i * 0.5f) * 0.5f + 0.5f) *
          size.height
        drawRoundRect(
          brush = Brush.verticalGradient(
            listOf(Color(0xFF22D3EE), Color(0xFF818CF8)),
          ),
          topLeft = Offset(i * gap, size.height - h),
          size = Size(gap * 0.5f, h),
          cornerRadius = CornerRadius(4f, 4f),
        )
      }
    }
  }
}