-
-
Save iniyanmurugavel/f7fd7e978c4b245c59f7ab9c3d2e7219 to your computer and use it in GitHub Desktop.
Super Mario inspired star animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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