Skip to content

Animation

Isometric uses withFrameNanos for vsync-aligned animation. This ties updates to the display refresh rate, producing smooth motion without wasted work. Do not use delay-based loops for animation.

Spin an octahedron continuously by incrementing the rotation angle each frame:

@Composable
fun SpinningScene() {
var angle by remember { mutableDoubleStateOf(0.0) }
LaunchedEffect(Unit) {
while (true) {
withFrameNanos { frameTimeNanos ->
angle += 0.02
}
}
}
IsometricScene {
Shape(
geometry = Octahedron(Point.ORIGIN),
rotation = angle,
rotationOrigin = Point(0.5, 0.5, 0.5)
)
}
}

Combine ForEach with a time-varying offset to create a rippling grid:

@Composable
fun WaveScene() {
var time by remember { mutableDoubleStateOf(0.0) }
LaunchedEffect(Unit) {
while (true) {
withFrameNanos { time += 0.02 }
}
}
IsometricScene {
ForEach((0 until 5).toList()) { i ->
ForEach((0 until 5).toList()) { j ->
val z = sin(time + i * 0.5 + j * 0.3) * 0.5
Shape(
geometry = Prism(Point(i.toDouble(), j.toDouble(), z)),
color = IsoColor(33, 150, 243)
)
}
}
}
}

For more animation recipes — color cycling, pulsing scale, orbiting shapes, staggered entrances — see Animation Patterns.