0Pricing
Jetpack Compose Academy · درس

‏DrawScope: الخطوط والمستطيلات والدوائر

ارسم العناصر الأساسية على اللوحة

‏DrawScope: الخطوط والمستطيلات والدوائر درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

ماذا ستتعلم في «‏DrawScope: الخطوط والمستطيلات والدوائر»؟

ارسم العناصر الأساسية على اللوحة تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟

لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «‏DrawScope: الخطوط والمستطيلات والدوائر»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟

نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ‏DrawScope: الخطوط والمستطيلات والدوائر
  2. المسارات والتدرجات وأنماط المزج
  3. ‏drawWithCache والأداء
  4. بناء حلقة تقدم مباشرة
← العودة إلى Jetpack Compose Academy