# Floating in Space - Animations with Compose and Canvas

DevFeed: [Floating in Space - Animations with Compose and Canvas](<https://devfeed.tech/articles/floating-in-space-animations-with-compose-and-canvas-38492.md>)

Original publisher: [Read original article](<https://eevis.codes/blog/2024-10-06/floating-in-space-animations-with-compose-and-canvas/>)

Author: Eevis Panula

Published: 2025-06-11T04:12:06.370000Z

Content type: tutorial

Language: en

Sources: [Eevis Blog](<https://devfeed.tech/sources/eevis-blog.md>)

Topics: [Compose](<https://devfeed.tech/topics/compose.md>), [Canvas](<https://devfeed.tech/topics/canvas.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [animations](<https://devfeed.tech/tags/animations.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [code](<https://devfeed.tech/tags/code.md>), [compose](<https://devfeed.tech/tags/compose.md>), [snippet](<https://devfeed.tech/tags/snippet.md>)

## AI overview

A tutorial showing how to animate a space illustration built with Jetpack Compose and Canvas. It explains how to animate star sizes with repeating float multipliers at different rates and how to rotate a moon around a planet.

## Source excerpt

In my previous blog post, Paint the Stars -- Drawing with Compose and Canvas, I shared how I wanted to be better with Canvas and Compose and created an illustration with planets and stars. This blog post shares how to animate those elements. In the end, the result will look like this: Full code is available in this snippet. Animations Stars Let's start with the stars. In the previous blog post, we defined the Star data class like this: data class Star( val size: Float, val topLeft: Offset, val color: Color, ) From these values, we want to animate the size of the stars. We'll do it by defining a multiplier that we will use with the star sizes to create the effect of the stars twinkling. We do this with infiniteTransition and animateFloat: val infiniteTransition = rememberInfiniteTransition(label = "infinite") val starSizeMultiplierOne by infiniteTransition .animateFloat( initialValue = 1f, targetValue = 1.5f, animationSpec = infiniteRepeatable( animation = tween( durationMillis = 3000, easing = animationEasing, ), repeatMode = RepeatMode.Reverse, ), label = "starSizeMultiplierOne", ) For the starSizeMultiplierOne, we give the initial value of 1, meaning that as it will act as a multiplier, the size would be 1 * size. The target value is 1.5, and as the repeat mode is Reverse, the float will animate between the size multiplied by 1 and 1.5. This transition creates a growing and shrinking effect. As we want the stars to look realistic and not animate at the same speed, we need to define two animated multipliers. Let's define another one: val starSizeMultiplierTwo by infiniteTransition .animateFloat( initialValue = 0.7f, targetValue = 1.7f, animationSpec = infiniteRepeatable( animation = tween( durationMillis = 2300, easing = animationEasing, ), repeatMode = RepeatMode.Reverse, ), label = "starSizeMultiplierTwo", ) This one has a bit shorter animation duration, and the initial and target values are different, so the twinkling happens at a different rate from the first mu