Skip to content

Instantly share code, notes, and snippets.

@cp-hardik-p
Created March 29, 2022 10:48
Show Gist options
  • Save cp-hardik-p/e4943223d24051115d1bf3f11ff1f95b to your computer and use it in GitHub Desktop.
Save cp-hardik-p/e4943223d24051115d1bf3f11ff1f95b to your computer and use it in GitHub Desktop.
@Composable
fun CircleOffsetAnimation(infiniteTransition: InfiniteTransition) {
val easing = LinearOutSlowInEasing
val color by infiniteTransition.animateColor(
initialValue = Color(0xff712B75),
targetValue = Color(0xFFE4AEC5),
animationSpec = infiniteRepeatable(
animation = tween(1500, easing = easing),
repeatMode = RepeatMode.Reverse
)
)
val color2 by infiniteTransition.animateColor(
initialValue = Color(0xFFE4AEC5),
targetValue = Color(0xff712B75),
animationSpec = infiniteRepeatable(
animation = tween(1500, easing = easing),
repeatMode = RepeatMode.Reverse
)
)
val offsetX by animateValues(
values = listOf(0f, 100f, -100f, 0f),
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1500, easing = easing),
repeatMode = RepeatMode.Restart
)
)
val scale by animateValues(
values = listOf(1f, 10f, 10f, 10f, 1f),
animationSpec = infiniteRepeatable(
animation = tween(1500, easing = easing),
repeatMode = RepeatMode.Restart
)
)
Canvas(
modifier = Modifier
.padding(top = 16.dp)
.size(100.dp)
) {
drawCircle(
color = Color.LightGray,
)
drawCircle(
color = color2,
radius = 80f + scale * 4f,
center = Offset(-offsetX + this.center.x, this.center.y)
)
drawCircle(
color = color,
radius = 80f + scale * 4f,
center = Offset(offsetX + this.center.x, this.center.y)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment