# Exploring Jetpack Compose Canvas: the power of drawing

DevFeed: [Exploring Jetpack Compose Canvas: the power of drawing](<https://devfeed.tech/articles/exploring-jetpack-compose-canvas-the-power-of-drawing-25942.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/exploring-jetpack-compose-canvas-the-power-of-drawing-8cc60815babe?source=rss-cbfc736ddcd3------2>)

Author: Julien Salvi

Published: 2021-03-19T16:38:56Z

Content type: tutorial

Language: en

Sources: [Stories by Julien Salvi on Medium](<https://devfeed.tech/sources/stories-by-julien-salvi-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Canvas](<https://devfeed.tech/topics/canvas.md>), [Android](<https://devfeed.tech/topics/android.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Code](<https://devfeed.tech/topics/code.md>), [Development](<https://devfeed.tech/topics/development.md>), [Google](<https://devfeed.tech/topics/google.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [animation](<https://devfeed.tech/tags/animation.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [code](<https://devfeed.tech/tags/code.md>), [component](<https://devfeed.tech/tags/component.md>), [compose](<https://devfeed.tech/tags/compose.md>), [function](<https://devfeed.tech/tags/function.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [library](<https://devfeed.tech/tags/library.md>), [ui](<https://devfeed.tech/tags/ui.md>)

## AI overview

A tutorial on using Canvas with Jetpack Compose to draw and animate shapes and text in Android applications. It explains the Canvas composable, DrawScope, coordinate origin, drawing styles, colors and brushes, and demonstrates a smiley face built from circles, arcs and rectangles. The examples are based on Compose 1.0.0-beta02, whose API methods may change.

## Source excerpt

In this article, I will share my experience of using Canvas with Jetpack Compose, which is the new UI toolkit made by Google. The Android Dev Challenge #2 gave me the opportunity to learn tons of things about Canvas and how to take advantage of it to draw and animate shapes or texts in a very nice way. Most of the code samples are based on the project below: Oleur/TimePack-CountPose Disclaimer: the code samples are based on Compose 1.0.0-beta02. The API methods might change in a near future.First steps with Canvas If you are familiar with the Android View canvas methods you won't be lost with the one from Jetpack Compose. All function names are same and some of them are even more explicit when dealing the Path API for example: relativeQuadraticBezierTo() instead of rQuadto() to curve a segment of the path. If you are not familiar with the native Android Canvas, I highly recommend to take a look at this article by Rebecca Franks to have a great introduction to the Android Canvas. Getting Started with Drawing on the Android Canvas 🖼 With Jetpack Compose, there is a Composable that is part of the UI component library called Canvas to unleash the power of drawing in your application. We are going to draw a smiley face with simple shapes (circle, arc and rectangles) to show its capabilities. https://medium.com/media/4c07f10b71cb6c5a87c46a02a3fa31b0/href The onDraw lambda on the Canvas give us access to the DrawScope. This scope is allowing us to draw everything we want in the Canvas. Remember that the origin (x=0, y=0) of the Canvas is located at the top left. Canvas with x-y axis and origin at top left To draw the head of the smiley face, we are going to draw a circle with a stroke style. If we let the style empty, it will be filled by default. All draw methods accept a Color or a Brush (used for adding gradients with a list of colors). To set the radius, we have access to the dimension of the current drawing environment with size provided by the the DrawScope in order