0Pricing
Jetpack Compose Academy · レッスン

DrawScope:線、矩形、円

キャンバスに基本図形を描画します。

「DrawScope:線、矩形、円」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Meet the Canvas

The Canvas Composable hands you a blank drawing surface. Inside it you paint pixels directly instead of stacking other Composables.

Canvas(modifier = Modifier.size(200.dp)) {
    // drawing goes here
}

Inside DrawScope

The lambda you pass to Canvas runs inside a DrawScope. That receiver gives you draw functions and the current size to work with.

Know Your Size

DrawScope exposes size, the area you can paint. Read size.width and size.height so your art scales to whatever space it gets.

Canvas(Modifier.fillMaxSize()) {
    val w = size.width
    val h = size.height
}

Draw a Line

Use drawLine to connect two points. You pass a color, a start Offset, an end Offset, and a stroke width.

drawLine(
    color = Color.Blue,
    start = Offset(0f, 0f),
    end = Offset(size.width, size.height),
    strokeWidth = 4f
)

Pixels Are Floats

Every coordinate here is a Float in pixels, not dp. The origin (0,0) sits at the top-left and x grows right, y grows down.

Offset Points the Way

An Offset is just an x and y pair. You will build almost every shape position from Offsets, so they show up everywhere on the canvas.

val center = Offset(size.width / 2, size.height / 2)

Draw a Rectangle

Call drawRect with a color, a topLeft Offset, and a Size. Leave topLeft out and it fills the whole canvas for you.

drawRect(
    color = Color.Green,
    topLeft = Offset(20f, 20f),
    size = Size(100f, 60f)
)

Draw a Circle

Use drawCircle with a color, a radius, and a center Offset. Center it on the canvas and you get a perfectly placed dot.

drawCircle(
    color = Color.Red,
    radius = 50f,
    center = center
)

Fill or Stroke

Each shape takes a style. The default is solid Fill, but pass Stroke to draw just the outline with a width you choose.

drawCircle(
    color = Color.Black,
    radius = 50f,
    style = Stroke(width = 6f)
)

Control Transparency

Pass an alpha between 0f and 1f to fade any shape. Stack a few translucent circles and you get a soft layered glow.

drawCircle(color = Color.Magenta, radius = 60f, alpha = 0.4f)

Order Is Layering

Draw calls paint in order, so later shapes sit on top of earlier ones. Think of it like dropping cutouts onto a page one by one.

Quick Check

Where does the canvas coordinate system begin?

Recap

You learned the Canvas basics: draw inside DrawScope, read size, and paint lines, rects, and circles with Offsets and float pixels. Order is everything! 🎨

よくある質問

「DrawScope:線、矩形、円」レッスンは無料ですか?

はい。「DrawScope:線、矩形、円」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。

「DrawScope:線、矩形、円」で何を学びますか?

キャンバスに基本図形を描画します。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Jetpack Compose Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「DrawScope:線、矩形、円」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このJetpack Compose Academyレッスンでコードを書いて実行できますか?

はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. DrawScope:線、矩形、円
  2. パス、グラデーション、ブレンドモード
  3. drawWithCacheとパフォーマンス
  4. ライブ進捗リングを作る
← Jetpack Compose Academyに戻る