Skip to content

Instantly share code, notes, and snippets.

@Kyriakos-Georgiopoulos
Last active October 28, 2025 11:08
Show Gist options
  • Select an option

  • Save Kyriakos-Georgiopoulos/8391754c1f4c9c27dcb7ef226d28e433 to your computer and use it in GitHub Desktop.

Select an option

Save Kyriakos-Georgiopoulos/8391754c1f4c9c27dcb7ef226d28e433 to your computer and use it in GitHub Desktop.
Super Mario inspired star animation
/*
* Copyright 2025 Kyriakos Georgiopoulos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@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