@Composable
fun Cube() {
// Draw the front face of the cube
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Blue)
)
// Draw the right face of the cube
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Green)
.graphicsLayer(rotationZ = 90f)
)
// Draw the top face of the cube
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Red)
.graphicsLayer(rotationX = 90f)
)
}
@Composable
fun RotatingCube() {
val rotationState = rememberInfiniteTransition()
val angle by rotationState.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 2000, easing = LinearEasing)
)
)
Box(
modifier = Modifier
.fillMaxSize()
.graphicsLayer(
rotationX = angle,
rotationY = angle
)
) {
Cube()
}
}
@Composable
fun MyScreen() {
RotatingCube()
}