Skip to content

Instantly share code, notes, and snippets.

@Kyriakos-Georgiopoulos
Created June 8, 2025 15:42
Show Gist options
  • Save Kyriakos-Georgiopoulos/8391754c1f4c9c27dcb7ef226d28e433 to your computer and use it in GitHub Desktop.
Save Kyriakos-Georgiopoulos/8391754c1f4c9c27dcb7ef226d28e433 to your computer and use it in GitHub Desktop.
Super Mario inspired star animation
@Composable
fun StarAnimation() {
val scope = rememberCoroutineScope()
val offsetY = remember { Animatable(0f) }
val rotation = remember { Animatable(0f) }
var hasLaunched by remember { mutableStateOf(false) }
fun launchAnimation() {
hasLaunched = true
scope.launch {
offsetY.snapTo(0f)
rotation.snapTo(0f)
launch {
offsetY.animateTo(
targetValue = -450f,
animationSpec = tween(durationMillis = 800, easing = FastOutSlowInEasing)
)
}
launch {
rotation.animateTo(
targetValue = 720f,
animationSpec = tween(durationMillis = 900, easing = LinearEasing)
)
}
}
}
Box(
modifier = Modifier
.fillMaxSize()
.padding(32.dp),
contentAlignment = Alignment.Center
) {
if (hasLaunched) {
Icon(
imageVector = Icons.Default.Star,
contentDescription = "Animated Star",
tint = Color(0xFFFFD700),
modifier = Modifier
.size(120.dp)
.graphicsLayer {
translationY = offsetY.value - 100f
rotationY = rotation.value
}
)
}
Button(
modifier = Modifier.size(
width = 200.dp,
height = 58.dp
),
onClick = ::launchAnimation,
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFFFFD700)
)
) {
Text(
text = "Launch Star",
fontSize = 20.sp,
color = Color.Black
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment