Skip to content

Instantly share code, notes, and snippets.

@maiatoday
Created May 26, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maiatoday/41cc66392d7008fb9a196f4eb48f6558 to your computer and use it in GitHub Desktop.
Save maiatoday/41cc66392d7008fb9a196f4eb48f6558 to your computer and use it in GitHub Desktop.
LifeSaver
@Composable
fun LifeSaver(rainbow: List<Color> = SkittlesRainbow) {
val color by rainbowState(rainbow = rainbow, duration = 2000)
val highlight by rainbowState(PastelRainbow, 2000)
val infiniteTransition = rememberInfiniteTransition()
val arcAngle1 by infiniteTransition.animateFloat(
initialValue = 0F,
targetValue = 180F,
animationSpec = infiniteRepeatable(
animation = tween(5000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
val arcAngle2 by infiniteTransition.animateFloat(
initialValue = 180F,
targetValue = 360F,
animationSpec = infiniteRepeatable(
animation = tween(5000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
Canvas(
modifier = Modifier
.size(80.dp)
) {
drawCircle(
color = color,
radius = 40.dp.toPx(),
style = Stroke(width = 40.dp.toPx(), cap = StrokeCap.Round)
)
drawCircle(
color = highlight,
radius = 24.dp.toPx(),
style = Stroke(width = 2.dp.toPx(), cap = StrokeCap.Round)
)
drawCircle(
color = highlight,
radius = 55.dp.toPx(),
style = Stroke(width = 2.dp.toPx(), cap = StrokeCap.Round)
)
drawArc(
color = highlight,
startAngle = arcAngle1,
sweepAngle = 90f,
useCenter = false,
style = Stroke(width = 4.dp.toPx(), cap = StrokeCap.Round),
)
drawArc(
color = highlight,
startAngle = arcAngle2,
sweepAngle = 90f,
useCenter = false,
style = Stroke(width = 4.dp.toPx(), cap = StrokeCap.Round),
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment